PDA

View Full Version : 2 Identical JsonStores, 1 won't load



taelo
16 Dec 2010, 12:14 PM
I'm not sure if this is right or wrong, but I am trying to load my JsonStores from a database as soon as the app loads. These two stores are configured the exact same way, and are called the exact same way, however, the user list generates an error on line 25345 of ext-all-debug (f = Record.prototype.fields, fi = f.items, fl = f.length, v;)

Here is the store that works:

var patchComboStore = new Ext.data.Store({
id : 'patchComboStore1',
proxy : new Ext.data.HttpProxy({
url : 'get-patch-list.php?task=getPatch'
}),
reader : new Ext.data.JsonReader({
root : 'data',
fields : [
{name: 'patch_id', mapping: 'patch_id'},
{name: 'patch_name', mapping: 'patch_name'}
]
})
});Here is the store that won't load:

var userComboStore = new Ext.data.JsonStore({
id : 'userComboStore1',
proxy : new Ext.data.HttpProxy({
url : 'get-user-list.php?task=getUsers'
}),
reader : new Ext.data.JsonReader({
root : 'dataUsers',
fields : [
{name: 'user_id', mapping: 'user_id'},
{name: 'user_name', mapping: 'user_name'}
]
})
});Here is how I am trying to call the load function:

if( !Ext.isDefined(patchComboStore.totalLength) )
patchComboStore.load();

if( !Ext.isDefined(userComboStore.totalLength) )
userComboStore.load();

EDIT: I was mistaken, both stores are loading data as indicated by Firebug. However, with the user store configured to load, I get the error indicated in the first paragraph (record is undefined).

fay
16 Dec 2010, 2:21 PM
FYI, JsonStore is automatically configured with a JsonReader so there is no need to create a new one. Try:



var userComboStore = new Ext.data.JsonStore({
id : 'userComboStore1',
url : 'get-user-list.php?task=getUsers',
root : 'dataUsers',
idProperty: 'user_id',
fields : [
{name: 'user_id', mapping: 'user_id'},
{name: 'user_name', mapping: 'user_name'}
]
});


If that doesn't work check the json response you can see in FireBug with www.jsonlint.com (http://www.jsonlint.com) to ensure that it is valid.

taelo
17 Dec 2010, 6:22 AM
Fay, thank you for the insight regarding the reader property, that was causing my problems.