PDA

View Full Version : Unable to access data from Store.



shakti_remo
22 Feb 2012, 10:19 PM
Hello all,

I am using Ext.data.Store that uses HttpProxy, and JsonReader to read response from server.


var store= new Ext.data.Store({
proxy:new Ext.data.HttpProxy({url:'/abddf/help/Georead',method:'GET'}),
reader:new Ext.data.JsonReader({
totalProperty:"CTpVeCountryList.totalrecord",
fields: [
{name: 'countrycode',type: 'string'},
{name: 'energy', type: 'int'},
{name: 'usedtime',type: 'int'},
],
id:"countrycode",
root:"CTpVeCountryList.tpvecountry"
})
});


My problem is with json that returned by server. there are two case with json format.

1) when response contains more than one record. Response Json looks like this.


{
"CTpVeCountryList": {
"tpvecountry": [
{
"countrycode": "BR",
"energy": 50,
"usedtime": 1
},
{
"countrycode": "CN",
"energy": 100,
"usedtime": 1
}
],
"message": "DB record",
"success": true,
"totalrecord": 2
}
}

2) when reponse contains only one record. Response Json looks like this.


{
"CTpVeCountryList": {
"tpvecountry": {
"countrycode": "BR",
"energy": 50,
"usedtime": 1
},
"message": "DB record",
"success": true,
"totalrecord": 1
}
}

for case 1) it is easy to get each record data throgh store.getRange() or store.data.each() to iterate each record.

but for case 2) when using store.getRange(), getting nothing.
when tried store.getRange().length, got 0 records in length,

when tried store.data.each(function(item, index,totalItem){}), it is not executed at all.

I tried my way to access data, when reponse json is like case 2), but not getting success in any case.

anyhow i need to access data for case 2).
I need expert help. How to access data form store when response json like case 2)?

Please help me out.
I would appreciate some help please
Thanks in advance

mitchellsimoens
23 Feb 2012, 6:50 AM
Case 2 it still needs to return an array.