PDA

View Full Version : JsonStore without URL provided ... cause I want to fill data myself ...



armandoxxx
7 Feb 2012, 6:36 AM
Hey guys ..

is there a way to load data in JsonStore with loadData() without providing URL config option ?

I already have data loaded for this store by some other store and that data is JSON, so loadData(myJSON, false) would be perfect if only I could create JsonStore without URL config.

my store


new Ext.data.JsonStore({
id : Ext.id(),
root : 'data',
idProperty : 'id',
fields: [
'id',
'title'
],
data : []
});


doing this just throws me JS error


ncaught TypeError: Cannot read property 'length' of undefined
Ext.extend.readRecordsext-all-debug.js:25347
Ext.data.Store.Ext.extend.loadDataext-all-debug.js:23866
Ext.data.Store.Ext.extend.constructorext-all-debug.js:23269
Ext.data.JsonStore.Ext.extend.constructor


Kind regards

Armando

mitchellsimoens
7 Feb 2012, 6:41 AM
You don't need a JsonStore then... just a regular Store with fields and data config set

armandoxxx
7 Feb 2012, 6:48 AM
hey

thank you for your fast reply...

trying this .. and still have the same error .. it's JSON data so at least I need JSON reader for it, or ?



new Ext.data.Store({
id : Ext.id(),
root : 'data',
reader : new Ext.data.JsonReader({

idProperty: 'id',
root: 'data',
totalProperty: 'count',
fields: [
{name: 'id', mapping: 'id'},
{name: 'name', mapping: 'name'}
]
}),
data : []
});


any suggestions ?

regards

Armando

armandoxxx
7 Feb 2012, 6:53 AM
figured it out:




data : {data: [], count : 0}



was the correct initial data needed !

Regards

Armando