PDA

View Full Version : Data.Store Question



StevenInc
9 Sep 2009, 6:00 PM
I have jason data that is stored in a local variable.
Like this:


var thisJSONdata = {
success:true,
rows:[
{
"TopId":"1",
"distName":"Ford and Cathy Griggs",
"mktLevel":"World Team",
"month":"June",
"thumbnail":"xxx.jpg",
"amount":"16,553.00",
},
{
"TopId":"2",
"distName":"Diana Lindsey",
"mktLevel":"Millionaire Team",
"month":"June",
"thumbnail":"xxx.jpg",
"amount":"14,311.00",
}
]
}

How can I read this data in to a data store?



var store = new Ext.data.Store({
url: thisJSONdata, //this does not work.
reader: new Ext.data.JsonReader({
root:'rows',
totalProperty: 'results',
id:'TopId'
}, [
'TopId',
'thumbnail',
'distName',
'mktLevel',
{name: 'month'},
{name: 'amount', type: 'float'},
])
});

store.load();


Thank you.

evant
9 Sep 2009, 6:04 PM
Correct, because the url expects a url.

Use store.loadData(myData);

StevenInc
9 Sep 2009, 6:16 PM
I tried this:



var store = new Ext.data.Store({
reader: new Ext.data.JsonReader({
root:'rows',
totalProperty: 'results',
id:'TopId'
}, [
'TopId',
'thumbnail',
'distName',
'mktLevel',
{name: 'month'},
{name: 'amount', type: 'float'},
])
});

store.load(thisJSONdata);


But the error I get back is:
this.proxy is undefined

Thanks again.

evant
9 Sep 2009, 7:02 PM
Read my post again ;)

jolitinh
9 Sep 2009, 7:42 PM
If you would like to read the JSON data from a local var, you could first load it into a MemoryProxy and then pass it to the store instead of using the url property.


var memoryProxy = new Ext.data.MemoryProxy(thisJSONData);
var store = new Ext.data.Store({
proxy: memoryProxy,
reader: new Ext.data.JsonReader({
root:'rows',
totalProperty: 'results',
id:'TopId'
}, [
'TopId',
'thumbnail',
'distName',
'mktLevel',
{name: 'month'},
{name: 'amount', type: 'float'},
])
});

store.load();

StevenInc
10 Sep 2009, 3:34 AM
Thank you jolitinh
Your solution worked well.

I appreciate the time you took to help me.

Condor
10 Sep 2009, 3:38 AM
Better solution:

var store = new Ext.data.Store({
data: thisJSONData,
reader: new Ext.data.JsonReader({
root:'rows',
totalProperty: 'results',
id:'TopId'
}, [
'TopId',
'thumbnail',
'distName',
'mktLevel',
{name: 'month'},
{name: 'amount', type: 'float'}
])
});
and don't call store.load().

StevenInc
10 Sep 2009, 6:18 AM
Thanks again.