PDA

View Full Version : Extending a Store



Stoot98
26 Sep 2010, 9:20 AM
Hi Guys

Im trying to put together a simple app to get to grips with the Touch framework. So far everything is good but I've hit a problem when trying to extend a Store.

In my app if I define a List's Store inline, as below, the code works perfectly.




...
store: new Ext.data.Store({
model: 'MainMenuItem',
data: [{
Text: 'Browse'
}, {
Text: 'Search'
}]
})
..

However if i move this Store into a seperate extended class it breaks with the error " cannot read property 'proxy' of undefined".




MainMenu = Ext.extend(Ext.data.Store, {

initComponent: function(){

Ext.apply(this, {
model: 'MainMenuItem',
data: [{
Text: 'Browse'
}, {
Text: 'Search'
}]

});

MainMenu.superclass.initComponent.call(this);
}

});

Does anyone have any ideas?

evant
26 Sep 2010, 2:59 PM
Stores have no initComponent method (it isn't a component).

You want:



MyStore = Ext.extend(Ext.data.Store, {
constructor: function(config){
Ext.apply(config, {
// stuff
});
MyStore.superclass.constructor.call(this, config);
}
});

Stoot98
27 Sep 2010, 1:13 AM
Doh! Of course, I knew it would be something stupid! Thanks a lot Evan, i appreciate it.

keckeroo
3 Nov 2010, 9:58 PM
In ExtJS I used to be able to do the following to create multiple stores with the same info at will :



Ext.ux.profileStore = Ext.extend(Ext.data.Store, {
url: '/ica/icaGetProfile.php',
reader: Ext.gc.profileReader
});

var abc = new Ext.ux.profileStore();
var xyz = new Ext.ux.profileStore();


but the following 'logic' no longer seems to apply in Sencha Touch



Ext.regModel('profileRecord', {
fields: [
{ name: 'userid', mapping: 'UserID' },
{ name: 'account', mapping: 'Account' }
]
});

Ext.ux.profileStore = Ext.extend(Ext.data.Store, {
model: 'profileRecord',
proxy: {
type: 'ajax',
url: '/ica/icaGetProfile.php',
reader: { root: 'records' }
}
});

var abc = new Ext.ux.profileStore();
var xyz = new Ext.ux.profileStore();


I get a runtime error of 'Result of expression: 'this.model' [undefined] is not an object.

Any help would be greatly appreciated on how i can extend a store to easily create multiple
versions of it.

Thank you!