在 ExtJs 中构建 TreePanel

Build TreePanel in ExtJs

请求时,服务器returns这样一个复杂的对象。内容其实多了很多,但是本质还是很清楚的,有objects和他们的children。

{"data":
{"accesslist":
[{"id":1,"parentID":0,"groupName":"doctor","pointCode":"patient.view","pointName":"Patien data","pointDescription":"","children":
[{"id":2,"parentID":1,"groupName":"doctor","pointCode":"patient.personal.info","pointName":"Show patient data","pointDescription":""}]
}]
}
}

我需要将这个对象放在 TreePanel 中,请告诉我该怎么做?

我试过了,但是不行。

var fullAccessCarribean = Ext.create('Ext.data.TreeStore', {
    proxy: {
        url: '/CardioService/securitymanager',
        method: 'post',
        type: 'ajax',
        extraParams:{
            mode: 'accesslist',
        },
        reader: {
            root: 'data.accesslist'
        }
    },
    root:{
        expanded: true,
    }
});


Ext.define('Ext.Modules.AdminGridForm.SettingsPanel.AccessPanel.AccessTreeGrid.AccessTreeGrid', {
    extend: 'Ext.tree.Panel',    
    alias: 'widget.accesstreegrid',

    flex: 1,

    layout: {
        type: 'hbox',
        align: 'stretch'
    },

    store: fullAccessCarribean,
});

使用 parentIdProperty 加载包含对父级的引用的平面列表。在你的情况下,它应该是:

parentIdProperty: 'parentID'