我正在将我的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上调用load函数时出现错误。

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"
                }]
            }]
        }]
    }]
  }
}

最佳答案

它期望对于每个子节点集重复根。因此,对于“ child ”,它也在尝试读取“Data.items”。

如果您不能更改数据结构,则根也可以是一个函数,例如:

root: function(o) {
    if (o.Data) {
        return o.Data.items;
    } else {
        return o.children;
    }
}

关于javascript - ExtJs4 Json TreeStore?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6263380/

10-10 13:11