PDA

View Full Version : Facing Problem while trying to create Custom Store



jai@15
19 Feb 2015, 10:31 PM
Hi ,

I Have created a custom store without specifying model (directly gave fields) using constructor in ExtJS 4.1.0 it was working fine without any issues or warnings pls find the below code :

Ext.define('ApplicationSetupStore', {
extend: 'Ext.data.Store',
config: {
url: null
},
constructor: function(currentObject) {

Ext.applyIf(this, {

fields: ['abc', 'abcd', 'abcde', 'abcdef'],
proxy: {
method: 'GET',
url: currentObject.url,
type: 'ajax',
extraParams: {
masiGroupCode: currentObject.groupCode,
masiSubCode: currentObject.subCode
},
reader: {
type: 'json',
root: 'data'
}
},
autoLoad: currentObject.autoLoad


});
this.callParent(arguments);
//everything breaks if you forget this
}
});

now i am trying to migrate from ExtJS 4.1.0 to 5.0.0 as there was an error message that you are trying to create store without Model so i created a model and trying to inject to Store :-

Ext.define('AppData', {
extend: 'Ext.data.Model',
fields: ['abc', 'abcd', 'abcde', 'abcdef'],
});
Ext.define('ApplicationSetupStore', {
extend: 'Ext.data.Store',
config: {
url: null
},
constructor: function(currentObject) {
Ext.applyIf(this, {
model: 'AppData',
proxy: {
method: 'GET',
url: currentObject.url,
type: 'ajax',
extraParams: {
masiGroupCode: currentObject.groupCode,
masiSubCode: currentObject.subCode
},
reader: {
type: 'json',
root: 'data'
}
},
autoLoad: currentObject.autoLoad


});
this.callParent(arguments);
}
});

now i am facing a problem when this.callParent(arguments); was executed
Object AppData has no method 'getProxy'

now i am totaly confused with this.callParent() ,what exactly it does. pls help me to overcome this issue.

Thank You

jai@15
23 Feb 2015, 12:53 AM
As i am trying to provide basic configuration required proxy at the time of Calling Parent constructor , there was an ambiguity and Improper result.

so now i am calling callparent before setting my config by ussing setters.

pls check the below code :-

Ext.define('ApplicationSetupStore', {
extend: 'Ext.data.Store',
requires: ['AppData'],
url: null,
groupCode: null,
subCode: null,
autoLoad: false,
model: 'AppData',
constructor: function(currentObject) {
currentObject = currentObject || {};
this.callParent([currentObject]);
var myproxy = {
method: 'GET',
url: currentObject.url,
type: 'ajax',
extraParams: {
masiGroupCode: currentObject.groupCode,
masiSubCode: currentObject.subCode
},
reader: {
type: 'json',
rootProperty: 'data'
}
};
this.setProxy(myproxy);




}
});

Correct me if i am wrong.