Reputation: 21
We get a response in JSON format but we're unable to fetch and print the data.
var dstore = Ext.getStore('DomesticStore');
dstore.sync();
dstore.load();
console.log(dstore.getData().items);
// this line prints the output but unable to fetch inside array data.
Upvotes: 2
Views: 527
Reputation: 970
I have an application that gets JSON data. When you get the store call the on method. Then access the data by using the records array.
var Store1 = Ext.getStore('DomesticStore').on('load', function (store, records, successful, operation, eOpts) {
if(successful == false){
console.log("Could not load store. ");
}
var e;
for (var i = 0; i < records.length; i++) {
e = records[i];
console.log(e.get('elementname'));
}
});
This will get go through the JSON array and get each value of whatever the field name is.
My JSON data looks like this
{
"countries": [
{
"name": "United States",
"2001": 128500000,
"2002": 141800000,
"2003": 160637000,
"2004": 184819000,
"2005": 203700000,
"2006": 229600000,
"2007": 249300000,
"2008": 261300000,
"2009": 274300000,
"2010": 278900000,
leaf: true
}
]
}
I use that code to get each country from the records array and then the name field of each.
Upvotes: 1