Javascript Sencha touch以与JSON嵌套相同的方式关联模型
我的json输出是:Javascript Sencha touch以与JSON嵌套相同的方式关联模型,javascript,json,sencha-touch,Javascript,Json,Sencha Touch,我的json输出是: {"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":"
{"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"}]}}
--我希望我的模型与结果和数据嵌套,这样在存储上设置autoLoad:true时,应该访问流上的key:value。但是我的console.log提供[]。我在我的模型中的某个地方出错了,请帮助
--这是我的型号
Ext.regModel('Gmt',
{'Result':
{'Data':
[
{name:'gmt_id',type:'string'},
{name:'Location',type:'string'}
]
}
});
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");
}
这是我要加载数据的存储: 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 });
--访问键:此处的值参数 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 });
} }, autoLoad: true });
我自己解决了 --更改存储根目录 --将“Result.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:'Result.Data' }, afterRequest: function (request, success) { if (success) { console.log("success"); } else { console.log("failed"); } } }, autoLoad: true });