我正在将ExtJs3应用程序迁移到ExtJs4 在ExtJs3中,我有一个树形网格,它有一个加载器来加载树数据,如下所示:
loader: new Ext.tree.TreeLoader({
dataUrl: 'Department/DepartmentTree',
nestedRoot: 'Data.items'
})
所以我试图在ExtJs4中创建一个treeStore,如下所示:
var store = Ext.create('Ext.data.TreeStore', {
model: 'DepartmentTreeModel',
folderSort: true,
proxy: {
type: 'ajax',
url: 'Department/DepartmentTree',
reader: {
type: 'json',
root: 'Data.items'
}
}
});
当我在上面的商店Cannot read property 'items' of undefined
上调用加载函数时出现错误。
JSON响应如下所示:
{
"Data":{
"__type":"ListWrapperOfDepartmentTreeNodewnEzJCii:#PortalMvc.Global.Classlibrary.Model.Ui.JSONWrappers",
"items":[{
"ActualHeadcount":0,
"Headcount":0,
"Leavers":0,
"ParentId":"~~",
"Starters":0,
"children":[{
"ActualHeadcount":0,
"Headcount":0,
"Leavers":0,
"ParentId":"!#",
"Starters":0,
"children":[{
"ActualHeadcount":0,
"Headcount":0,
"Leavers":0,
"ParentId":"*w",
"Starters":0,
"children":[{
"ActualHeadcount":0,
"Headcount":0,
"Leavers":0,
"ParentId":"*z",
"Starters":0,
"children":[],
"iconCls":"admin_button",
"id":"*{",
"leaf":true,
"text":"Parking1_subtree1"
}]
}]
}]
}]
}
}
答案 0 :(得分:7)
它希望为每组子节点重复根。所以对于“孩子们”来说,它也试图阅读“Data.items”。
如果你不能改变数据结构,root也可以是一个函数,如:
root: function(o) {
if (o.Data) {
return o.Data.items;
} else {
return o.children;
}
}