Sencha-touch associate model in the same way JSON is nested
my json output is:
{"Result":
{"Data":
[{"gmt_id":"1","gmt":"-12:00","secondsDiff":"-43200","Location":"Baker IslanIsland"},
{"gmt_id":"2","gmt":"-11:00","secondsDiff":"-39600","Location":"American Samoa, Samoa"},
{"gmt_id":"3","gmt":"-10:00","secondsDiff":"-36000","Location":"Hawaii, Papeete"}]}}
--I want my Model to be nested with Result and Data, so that on setting autoLoad:true on the store, should access key:value on the flow. But my console.log gives[]. i am wrong somewhere in my model please help!!!
--this is my model
Ext.regModel('Gmt',
{'Result':
{'Data':
[
{name:'gmt_id',type:'string'},
{name:'Location',type:'string'}
]
}
});
this is my Store to load data:
var jsonStore = new Ext.data.Store({ model: "Gmt", proxy: { 开发者_开发知识库 type: 'ajax', url: 'gmt.php', //url: 'data.json', method: 'GET', // callback: console.log(response), reader: { type: 'json', //root: 'Data' root:'Result' // type:'json' }, afterRequest: function (request, success) { if (success) { console.log("success"); } else { console.log("failed"); }} }, autoLoad: true });
--access key:value parameters here
jsonStore.on('load', function(){
var lstArr = new Array();
var lstAr = new Array();
jsonStore.each(function(i) {
//var gmtdata = i.data.gmt_id;
// console.log(i);
lstArr.push(i.data.gmt_id);
lstAr.push(i.data.Location);
});
console.log(lstArr);
console.log(lstAr);
});
Solved it myself.
--Change the Store root
--Set 'Result.Data' as root
var jsonStore = new Ext.data.Store({
model: "Gmt",
proxy: {
type: 'ajax',
url: 'gmt.php',
//url: 'data.json',
method: 'GET',
// callback: console.log(response),
reader: {
type: 'json',
root:'Result.Data'
},
afterRequest: function (request, success) {
if (success) {
console.log("success");
} else {
console.log("failed");
}
}
},
autoLoad: true
});
精彩评论