-
14 Jan 2012 7:46 AM #1
Answered: Extend a Ext.data.Store and change some Parameters
Answered: Extend a Ext.data.Store and change some Parameters
Hello,
I have 8 stores like this in my App:
The only thing that makes the difference in these stores are the models an extraParams of the proxy.PHP Code:HR.stores.ConfigStore = new Ext.data.Store({
autoLoad : false,
model : 'Config',
proxy: {
type: 'scripttag',
url: 'xxx.php',
callbackKey: 'callback',
extraParams: {
method : 'config'
},
reader: {
type: 'json',
root: 'results'
}
}
});
Is it impossible to create a MainStore like this
and then extend this store several times and applying the mentioned differences?PHP Code:HR.stores.MainStore = new Ext.data.Store({
autoLoad : false,
proxy: {
type: 'scripttag',
url: 'xxx.php',
callbackKey: 'callback',
reader: {
type: 'json',
root: 'results'
}
}
});
I already tried some things I found here:
But I get errors like "Cannot read property 'proxy' of undefined"...PHP Code:HR.stores.ConfigStore = Ext.extend(HR.stores.MainStore, {
constructor:function (config) {
config = config || {};
Ext.applyIf(config, {
model:'Config',
proxy:{
extraParams:{
method:'config'
}
}
});
HR.stores.ConfigStore.superclass.constructor.call(this, config);
}
});
How has the extended store to look like?
Regards,
testmacher
-
Best Answer Posted by mitchellsimoensCode:
MainStore = Ext.extend(Ext.data.Store, { constructor : function(config) { config = config || {}; var extraParams = config.extraParams || this.extraParams; Ext.applyIf(config, { model : 'Config', proxy : { extraParams : extraParams } }); MainStore.superclass.constructor.call(this, config); } });Code:UserStore = Ext.extend(MainStore, { constructor : function(config) { this.extraParams = { foo : 'bar' }; UserStore.superclass.constructor.call(this, config); } });
-
15 Jan 2012 2:06 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
Code:MainStore = Ext.extend(Ext.data.Store, { constructor : function(config) { config = config || {}; var extraParams = config.extraParams || this.extraParams; Ext.applyIf(config, { model : 'Config', proxy : { extraParams : extraParams } }); MainStore.superclass.constructor.call(this, config); } });Code:UserStore = Ext.extend(MainStore, { constructor : function(config) { this.extraParams = { foo : 'bar' }; UserStore.superclass.constructor.call(this, config); } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
15 Jan 2012 7:14 PM #3
Hello,
thanks for the answer, but one problem remains if I do like this.
I get:
if I try to 'load' the store (the ConfigStore).PHP Code:Uncaught TypeError: Object function (config) {
this.extraParams = {
foo : 'bar'
};
ConfigStore.superclass.constructor.call(this, config);
} has no method 'load'
I also register like that:
What do I have to change there? Must the MainStore also be registered?PHP Code:Ext.regStore('app_configStore', ConfigStore);
Regards,
testmacher
-
17 Jan 2012 11:08 AM #4


Reply With Quote