最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ExtJs4 Json TreeStore? - Stack Overflow

programmeradmin8浏览0评论

I am migrating my ExtJs3 application to ExtJs4.
In ExtJs3 I had a tree grid which had a loader to load the tree data, like below:

loader: new Ext.tree.TreeLoader({ 
            dataUrl: 'Department/DepartmentTree', 
            nestedRoot: 'Data.items'
    })

So I am trying to create a treeStore in ExtJs4 like below:

   var store = Ext.create('Ext.data.TreeStore', {
        model: 'DepartmentTreeModel',
        folderSort: true,
        proxy: {
            type: 'ajax',
            url: 'Department/DepartmentTree',
            reader: {
                type: 'json',
                root: 'Data.items'
            }
        }
    });

I get an error when I call the load function on the above store Cannot read property 'items' of undefined.

The JSON response looks like this:

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

I am migrating my ExtJs3 application to ExtJs4.
In ExtJs3 I had a tree grid which had a loader to load the tree data, like below:

loader: new Ext.tree.TreeLoader({ 
            dataUrl: 'Department/DepartmentTree', 
            nestedRoot: 'Data.items'
    })

So I am trying to create a treeStore in ExtJs4 like below:

   var store = Ext.create('Ext.data.TreeStore', {
        model: 'DepartmentTreeModel',
        folderSort: true,
        proxy: {
            type: 'ajax',
            url: 'Department/DepartmentTree',
            reader: {
                type: 'json',
                root: 'Data.items'
            }
        }
    });

I get an error when I call the load function on the above store Cannot read property 'items' of undefined.

The JSON response looks like this:

    {
"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"
                }]
            }]
        }]
    }]
  }
}
Share edited Jun 7, 2011 at 10:33 shane87 asked Jun 7, 2011 at 9:41 shane87shane87 3,12013 gold badges52 silver badges66 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

It expects the root to be repeated for each set of child nodes. So for "children" it's also trying to read "Data.items".

If you can't alter the data structure, the root can also be a function, something like:

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

评论列表(0)

  1. 暂无评论