PDA

View Full Version : Store with type memory not loading the data



sandeepmnit35
5 Dec 2012, 1:01 AM
I am getting json response and am trying to put json in store but it is not loading it properly.





Ext.Ajax.request({
url: url,
success: function(xhr) {
response = Ext.JSON.decode(xhr.responseText.trim()); //alert(xhr.responseText.trim());
for(i=0;i< response.data.length; i++) { instancestore[i] = Ext.create('Ext.data.Store', {
autoLoad: true,
model: 'RA.model.DataModel',
proxy: {
type: 'memory',
data: response,
reader: {
type: 'json',
root: 'data'
}
}
});
}


My Json output is :



{ "data":
[{ "0": [{ "DowntimeEvents": 179, "DowntimeHours": 78355 }] }, { "1": [{ "DowntimeEvents": 176, "DowntimeHours": 97835 }] }, { "2": [{ "DowntimeEvents": 140, "DowntimeHours": 100501 }] }]}


I tried below code but it is passing null value of DowntimeEvents and DowntimeHours in the store.


Ext.Ajax.request({
url: url,
success: function(xhr) {
response = Ext.JSON.decode(xhr.responseText.trim());
//alert(xhr.responseText.trim());
for(i=0;i< response.data.length; i++) { alert(response.data[0].DowntimeEvents);

instancestore[i] = Ext.create('Ext.data.Store', {
autoLoad: true,
model: 'RA.model.DataModel',
data: response.data[i],
proxy: {
type: 'memory',
reader: {
type: 'json',

}
}
});
}

mitchellsimoens
6 Dec 2012, 1:17 PM
First off you have some config that are in the wrong place or are not truly valid:


var store = Ext.create('Ext.data.Store', {
model : 'RA.model.DataModel',
data : response,
proxy : {
type : 'memory',
reader : {
rootProperty : 'data'
}
}
});

Your response is a little too nested, instead of this:


{
"data" : [
{
"0" : [
{
"DowntimeEvents" : 179,
"DowntimeHours" : 78355
}
]
},
{
"1" : [
{
"DowntimeEvents" : 176,
"DowntimeHours" : 97835
}
]
},
{
"2" : [
{
"DowntimeEvents" : 140,
"DowntimeHours" : 100501
}
]
}
]
}

should really be:

{
"data" : [
{
"DowntimeEvents" : 179,
"DowntimeHours" : 78355
},
{
"DowntimeEvents" : 176,
"DowntimeHours" : 97835
},
{
"DowntimeEvents" : 140,
"DowntimeHours" : 100501
}
]
}

and you are good now.

sandeepmnit35
6 Dec 2012, 8:51 PM
I need to store data on index basis for different date thats why I am using instance[i] and sending indexes in json response so I can store the data on index basis.

My json is having data for 3 different date and I am using slider with play button to render the graph for 3 different date so I need to have data on index basis in store .

Can you please let me know how can I do this?
Thanks