PDA

View Full Version : Subclassing JsonStore



th23
24 Sep 2009, 1:19 AM
Hi!

I'm a newbie to ExtJs and got the following Problem. Maybe an experienced Ext Geek can help me?

I created this specialization of Json Reader since I need it in more than one place of the code. Its configued to read 'package' records encoded as JSON. ('packages' has a app - specific meaning and has nothing to do with packages in a programming language manner)



/**
* @class
*
* A JsonStore specialization
*/
AppNS.data.JsonPackageStore = function(){
AppNS.data.JsonPackageStore.superclass.constructor.call(this, {
idProperty : 'databaseId',
root : 'packages',
fields : [
'databaseId','title', 'language', 'tvRights', 'price', 'published'
]
});
};
Ext.extend(AppNS.data.JsonPackageStore, Ext.data.JsonStore);
And i will use it this way:



store = new AppNS.data.JsonPackageStore({
url: '?module=TV.Packages&method=getPackages&random=' + Math.random(),
storeId: 'packagesStore'
});
I got this error in FB:

this.proxy is undefined
http://mydomain/js/ext-3.0.0/ext-all-debug.js
Line 30838

When I run the code without subclassing Ext.data.JsonStore the example will run.



store = new Ext.data.JsonStore({
url: '?module=TV.Packages&method=getPackages&random=' + Math.random(),
// store configs
storeId: 'packagesStore',
idProperty : 'databaseId',
root : 'packages',
fields : [
'databaseId','title', 'language', 'tvRights', 'price', 'published'
]
});Has anybody out there an idea what I made wrong?

27 Sep 2009, 6:25 PM
try this:



/**
* @class
*
* A JsonStore specialization
*/
AppNS.data.JsonPackageStore = function(config){
Ext.apply(this, config || {});

AppNS.data.JsonPackageStore.superclass.constructor.call(this, {
idProperty : 'databaseId',
root : 'packages',
fields : [
'databaseId','title', 'language', 'tvRights', 'price', 'published'
]
});
};
Ext.extend(AppNS.data.JsonPackageStore, Ext.data.JsonStore);

th23
28 Sep 2009, 12:08 AM
jgarcia's code works fine for me!



AppNS.data.JsonPackageStore = function(config){
Ext.apply(this, config || {});

I forgot the 'config' param in constructor and the Ext.apply(.. statement.

Thanks!

Condor
28 Sep 2009, 12:23 AM
The recommended way in Ext 3.x is:

AppNS.data.JsonPackageStore = Ext.extend(Ext.data.JsonStore, {
constructor: function(config){
AppNS.data.JsonPackageStore.superclass.constructor.call(this, Ext.apply({
idProperty : 'databaseId',
root : 'packages',
fields : [
'databaseId','title', 'language', 'tvRights', 'price', 'published'
]
}, config));
}
});
and for Ext 2.x it should be:

AppNS.data.JsonPackageStore = function(config){
AppNS.data.JsonPackageStore.superclass.constructor.call(this, Ext.apply({
idProperty : 'databaseId',
root : 'packages',
fields : [
'databaseId','title', 'language', 'tvRights', 'price', 'published'
]
}, config));
}
Ext.extend(AppNS.data.JsonPackageStore, Ext.data.JsonStore);

th23
28 Sep 2009, 12:34 AM
Thanks condor!