我的Store是这么定义的:Ext.define("NP.store.Menus", {
extend : "Ext.data.TreeStore",
model : "NP.model.Menu",
root : {
expanded : true,
text : "系统菜单",
},
proxy : {
type : "rest",
url : "menu",
reader : {
type : "json",
root : "data",//这里如果设置成data.content就不对
successProperty : "success"
}
}
});
服务器返回的JSON数据格式为:Js代码
{
"data": {
"content": [
{
"id": 1,
"name": "系统管理",
"url": null,
"title": "系统管理",
"icon": null,
"parent": null,
"children": [],
"roles": [],
"userGroups": []
}
]
},
"success": true
}
因为我的模型数据集合是在数据的data.content里,而如果Store.proxy.reader.root设置成data.content 就会报错:Uncaught TypeError: Cannot read property 'content' of undefined这是什么原因啊 ? 请指点啊Ext JSJavaScript
extend : "Ext.data.TreeStore",
model : "NP.model.Menu",
root : {
expanded : true,
text : "系统菜单",
},
proxy : {
type : "rest",
url : "menu",
reader : {
type : "json",
root : "data",//这里如果设置成data.content就不对
successProperty : "success"
}
}
});
服务器返回的JSON数据格式为:Js代码
{
"data": {
"content": [
{
"id": 1,
"name": "系统管理",
"url": null,
"title": "系统管理",
"icon": null,
"parent": null,
"children": [],
"roles": [],
"userGroups": []
}
]
},
"success": true
}
因为我的模型数据集合是在数据的data.content里,而如果Store.proxy.reader.root设置成data.content 就会报错:Uncaught TypeError: Cannot read property 'content' of undefined这是什么原因啊 ? 请指点啊Ext JSJavaScript
{
"data": {
"id": 1,
"name": "系统管理",
"url": null,
"title": "系统管理",
"icon": null,
"parent": null,
"children": [],
"roles": [],
"userGroups": []
},
"success": true
}
因为Data里面不仅包含了content还包含一些其他的信息,最好是不要改动后台代码
另外,root应该是children。当然,你也可以拿到json后,自己按从属关系往treestore里填加数据。
var node = root.createNode( {
id:data.content.id,
...
} );
root.appendChild(node);