PDA

View Full Version : problem with json datastore, what am i missing?



andresblanco
8 Nov 2010, 7:04 AM
if i define a datastore in the following way, it works:


ds = new Ext.data.JsonStore({
autoLoad: false,
url: 'json_servicios.php',
root: 'filas',
totalProperty: 'cant',
idProperty: 'key',
fields: ['nombre', 'servidor_web', 'key']
})


but if i extend JsonStore:


ds_serv = Ext.extend(Ext.data.JsonStore, {
autoLoad: false,
url: 'json_servicios.php',
root: 'filas',
totalProperty: 'cant',
idProperty: 'key',
fields: ['nombre', 'servidor_web', 'key']
});

and then i do the following:


ds = new ds_serv();
ds.load();

It makes the request (and the response is fine) but getRange() returns an empty array

:-|

plalx
8 Nov 2010, 7:29 AM
Are you sure that you are calling getRange() after the records have been loaded? (by listening to the load event)

andresblanco
8 Nov 2010, 8:08 AM
yes, i'm listening to the load event, thanks for the reply. The code is the same in both cases except for the object being created. In the first case it works but in the second it does not!

plalx
8 Nov 2010, 8:11 AM
When logging store.getCount(), does the store contains any records after the load?

Condor
8 Nov 2010, 8:16 AM
You can't extend a JsonStore that way!

You need to use:

ds_serv = Ext.extend(Ext.data.JsonStore, {
constructor: function(config){
ds_serv.superclass.constructor.call(this, Ext.apply({
autoLoad: false,
url: 'json_servicios.php',
root: 'filas',
totalProperty: 'cant',
idProperty: 'key',
fields: ['nombre', 'servidor_web', 'key']
}, config));
});

andresblanco
8 Nov 2010, 8:17 AM
getCount returns 0. It's really strange...

andresblanco
8 Nov 2010, 8:18 AM
!!! Thank you so much condor!! Is there any documentation that states the way the components should be extended?

plalx
8 Nov 2010, 8:38 AM
@Condor, Hehe, thx for pointing this out... it's funny, I never knew that but never ran into any errors. I was always defining the fields into the constructor.