ExtJS 4 Tree Store加载远程数据并在本地使用它

时间:2015-04-21 13:06:41

标签: extjs extjs4

我将我的树店定义为:

Ext.define('Portal.store.GroupsTreeStore', {
    extend: 'Ext.data.TreeStore',
    model: 'Portal.model.GroupTreeModel',

    autoLoad: false,

    proxy: {
        method: 'get',
        type: 'ajax',
        url: 'groups/get',
        reader: {
            type: 'json',
            successProperty: 'success',
            messageProperty: 'message',
            root: 'data'
        }
    },
    // Prevent auto loading
        root: {
        expanded: true,
        text: "",
        "data": []
    }
});

我的模特:

Ext.define('Portal.model.GroupTreeModel', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name', type: 'string'},
        {name: 'type', type: 'string'}
    ]
});

我收到的JSON数据如下:

{
    "success": true,
    "message": "ok",
    "data": [{
        "name": "group1",
        "type": "group",
        "expanded": true,
        "children": [{
            "name": "admin_2503",
            "type": "people",
            "leaf": true
        },
        {
            "name": "u1",
            "type": "people",
            "leaf": true
        },
        {
            "name": "u2",
            "type": "people",
            "leaf": true
        }]
    },
    {
        "name": "group2",
        "type": "group",
        "expanded": false,
        "leaf": false,
        "children": [{
            "name": "u5",
            "type": "people",
            "leaf": true
        }]
    }]
}

我想一次加载我的所有树存储数据并在本地工作后(例如搜索,过滤等),但是使用此存储配置,所有节点都显示未扩展,并且在展开操作上执行查询以提供{{1使用节点ID,接收相同的JSON并添加url: groups\getgroup1作为节点子节点。我应该如何为此目的配置我的商店?

更新视图定义:

group2

});

1 个答案:

答案 0 :(得分:1)

请查看此链接的答案,这可能会导致您遇到的问题。 Extjs4.2.1 - Load json to treepanel fails