Sencha Touch嵌套JSON-使用关联存储加载
我想在存储中加载嵌套的JSON,但数据没有正确映射。一个单一的regModel没有问题,但我无法让关联正常工作Sencha Touch嵌套JSON-使用关联存储加载,json,associations,sencha-touch,store,Json,Associations,Sencha Touch,Store,我想在存储中加载嵌套的JSON,但数据没有正确映射。一个单一的regModel没有问题,但我无法让关联正常工作 // JSON in test.json {"message" : { "returnCodes": [ { "value": "0", "code": "200", "description": "OK" }, { "value": "0
// JSON in test.json
{"message" : {
"returnCodes": [
{
"value": "0",
"code": "200",
"description": "OK"
},
{
"value": "0",
"code": "200",
"description": "OK"
}
]
}}
// Model with associations
Ext.regModel("ReturnCode", {
fields : [{
name : "value",
type : "string"
}, {
name : "code",
type : "string"
}, {
name : "description",
type : "string"
}],
belongsTo: "Message"
});
Ext.regModel("Message", {
hasMany: {
model : "ReturnCode",
name : "returnCodes"
}
});
// Store
var jobStore = new Ext.data.Store({
model : 'Message',
autoLoad: true,
proxy : {
type : 'ajax',
url: 'test.json',
reader : {
type : 'json',
root : 'message.returnCodes'
}
}});
// List
var list = Ext.extend( Ext.List, {
fullscreen : true,
store : jobStore,
grouped : false,
itemTpl : '<div>{code}</div>' // no output
});
//test.JSON中的JSON
{“信息”:{
“返回代码”:[
{
“值”:“0”,
“代码”:“200”,
“说明”:“确定”
},
{
“值”:“0”,
“代码”:“200”,
“说明”:“确定”
}
]
}}
//联想模式
Ext.regModel(“返回代码”{
字段:[{
名称:“值”,
类型:“字符串”
}, {
名称:“代码”,
类型:“字符串”
}, {
名称:“说明”,
类型:“字符串”
}],
belongsTo:“消息”
});
Ext.regModel(“消息”{
有许多:{
型号:“返回代码”,
名称:“返回代码”
}
});
//贮藏
var jobStore=新的Ext.data.Store({
模型:“消息”,
自动加载:对,
代理:{
键入:“ajax”,
url:'test.json',
读者:{
键入:“json”,
root:'message.returnCodes'
}
}});
//名单
变量列表=扩展(扩展列表{
全屏:对,
商店:jobStore,
分组:假,
itemTpl:'{code}'//没有输出
});
当我查看store时,每个数据都存储在store对象的raw部分中,但在data部分中没有任何内容。在两个returnCode对象的列表中都创建了一个listitem,但它们没有填充数据,因为映射没有成功->itemTpl没有获取数据。首先尝试声明消息模型,然后在消息模型中添加
associationKey:'returnCodes'
。同时将读卡器的根目录更改为消息