PDA

View Full Version : Accessing JSON fields



douggiefox
10 Nov 2009, 7:20 AM
Hi

I have a JsonStore that's returning data back to a grid. The grid's populating correctly but I have a few extra fields in the Json payload that I'd like to access. The format of the Json looks a bit like this:


{
"totalCount": 2,
"totalPremium": 20,
"results":
[
{
"netPremium": 10
},
{
"netPremium": 20
}
]
}



I'd like to access the 'totalPremium' field if possible.

Best

DF

Animal
10 Nov 2009, 7:22 AM
http://www.extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader&member=jsonData

aw1zard2
10 Nov 2009, 7:26 AM
You can configure like described in the JsonReader documentation.

http://www.extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader (http://www.extjs.com/forum/../deploy/dev/docs/?class=Ext.data.JsonReader)
(http://www.extjs.com/forum/../deploy/dev/docs/output/?class=Ext.data.JsonReader.html)

douggiefox
10 Nov 2009, 7:43 AM
...just not clear on how to access it...



store.on('load', function(){
//quotationStore.jsonData.totalNetPremium??

});



jsonData's undefined but my data is loaded.

I also tried assigning an object to the jsonData field but to no avail. Sure I'm missing something obvious that's right in front of me.

Best

DF

Animal
10 Nov 2009, 7:48 AM
Carefully look at what class that above link is.

http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Store&member=reader

Condor
10 Nov 2009, 7:49 AM
It's a config option of the reader, so you should have used:


store.on('load', function(){
var value = store.reader.jsonData.totalNetPremium;
...
});

douggiefox
10 Nov 2009, 8:02 AM
Thanks guys.

Animal: for trying to teach me something :-)
Condor: for the solution

DF