-
5 Dec 2012 1:01 AM #1
Store with type memory not loading the data
Store with type memory not loading the data
I am getting json response and am trying to put json in store but it is not loading it properly.
My Json output is :HTML Code: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' } } }); }
I tried below code but it is passing null value of DowntimeEvents and DowntimeHours in the store.HTML Code:{ "data": [{ "0": [{ "DowntimeEvents": 179, "DowntimeHours": 78355 }] }, { "1": [{ "DowntimeEvents": 176, "DowntimeHours": 97835 }] }, { "2": [{ "DowntimeEvents": 140, "DowntimeHours": 100501 }] }]}
HTML Code: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', } } }); }
-
6 Dec 2012 1:17 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
First off you have some config that are in the wrong place or are not truly valid:
Your response is a little too nested, instead of this:Code:var store = Ext.create('Ext.data.Store', { model : 'RA.model.DataModel', data : response, proxy : { type : 'memory', reader : { rootProperty : 'data' } } });
should really be:Code:{ "data" : [ { "0" : [ { "DowntimeEvents" : 179, "DowntimeHours" : 78355 } ] }, { "1" : [ { "DowntimeEvents" : 176, "DowntimeHours" : 97835 } ] }, { "2" : [ { "DowntimeEvents" : 140, "DowntimeHours" : 100501 } ] } ] }
{
"data" : [
{
"DowntimeEvents" : 179,
"DowntimeHours" : 78355
},
{
"DowntimeEvents" : 176,
"DowntimeHours" : 97835
},
{
"DowntimeEvents" : 140,
"DowntimeHours" : 100501
}
]
}
and you are good now.Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
6 Dec 2012 8:51 PM #3
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


Reply With Quote