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

ExtJS 4 Tree Store Load remote data and work with it locally

我将我的树商店定义为:

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

我想在本地使用它(例如搜索、过滤等)后立即加载我所有的树存储数据,但是使用这个存储配置所有节点都显示未扩展和扩展操作执行查询以提供 url: groups\get 与节点 ID,接收相同的 JSON 并添加 group1group2 作为节点子节点。为此,我应该如何配置我的商店?

更新 视图定义:

Ext.define('Portal.view.GroupsTree', {
extend: 'Ext.tree.Panel',

store: 'GroupsTreeStore',

border: false,
emptyText: 'No records found',
multiSelect: false,
rootVisible: false,

columns: [
    {
        xtype: 'treecolumn',
        dataIndex: 'name',
        flex: 1,
        sortable: true,
        text: 'Name'
    }
],

initComponent: function () {
    this.callParent(arguments);
}

});

请查看此 link 的答案,这可能是您遇到的问题的原因。 Extjs4.2.1 - Load json to treepanel fails