可以通过重写 Ext.data.TreeStore 的 load 方法,在数据请求回来后修改数据。具体操作如下:

  1. 创建一个继承自 Ext.data.TreeStore 的子类,并重写 load 方法:
Ext.define('MyTreeStore', {
    extend: 'Ext.data.TreeStore',

    load: function(options) {
        var me = this;

        options = options || {};

        options.callback = function(records, operation, success) {
            if (success) {
                me.modifyData(records);
            }

            Ext.callback(options.callback, options.scope || me, [records, operation, success]);
        };

        me.callParent([options]);
    },

    modifyData: function(records) {
        // TODO: modify data here
    }
});
  1. 在 modifyData 方法中修改数据,例如移除某个节点:
modifyData: function(records) {
    var rootNode = this.getRootNode();

    rootNode.cascadeBy(function(node) {
        if (node.get('id') === 'nodeToRemove') {
            node.remove();
        }
    });
}
  1. 使用自定义的 MyTreeStore 来加载数据:
var store = Ext.create('MyTreeStore', {
    proxy: {
        type: 'ajax',
        url: 'data.json'
    }
});

store.load();
ExtJS TreeStore 数据修改:远程请求后修改数据

原文地址: https://www.cveoy.top/t/topic/mkrm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录