Extjs 4.2.1 - config autoLoad:false失败

fre*_*yle 8 extjs extjs4 extjs4.2

我定义了一个treepanel扩展extend: 'Ext.tree.Panel',它具有initComponent函数

 Ext.define('Example', {
    extend: 'Ext.tree.Panel',
    title: 'Example',
    useArrows:false, 
    rootVisible: false,
    border: false,
    initComponent: function () {
        var store = Ext.create('Ext.data.TreeStore', {
            fields: [
                {name: 'id',     type: 'string'},
                {name: 'text',     type: 'string'}
            ],
            autoLoad : false, // not working
            proxy: {
                type: 'ajax',
                url: 'data.php',
                reader: {
                    type: 'json',
                    root: 'results'     
                }
            }

        });
        this.store = store;
        this.callParent(arguments);
    }
 });
Run Code Online (Sandbox Code Playgroud)

我尝试设置autoLoad: false但是当我创建我的时候总是加载treepanel

当我尝试配置下面的代码存储然后autoLoad: false工作但我的treepanel后加载是空白

                root: {
                    text: 'Ext JS',
                    id: 'src',
                    expanded: false // this 
                }
Run Code Online (Sandbox Code Playgroud)

我的json很好,如果不使用root配置就可以工作

({  "results": [
    { 
        id : '1' , 
        text : '1', 
        expanded: true, 
        results :[{ 
            id : '2' , 
            text : '2', 
            leaf:true
        }]
    },{ 
        id : '3' , 
        text : '3', 
        leaf:true
    }] 
})
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题.

Via*_*lov 5

您必须覆盖Ext.tree.Panel.setRootNode方法才能将商店的autoLoad属性考虑在内。

以下示例使用 ExtJS v4.2.2 进行测试。

Ext.define('Example', {
    extend: 'Ext.tree.Panel',
    title: 'Example',
    useArrows:false,
    rootVisible: false,
    border: false,

    /**
     * Override.
     */
    setRootNode: function() {
        if (this.getStore().autoLoad) {
            this.callParent(arguments);
        }
    },

    initComponent: function () {
        var store = Ext.create('Ext.data.TreeStore', {
            fields: [
                {name: 'id',     type: 'string'},
                {name: 'text',     type: 'string'}
            ],
            autoLoad : false,
            proxy: {
                type: 'ajax',
                url: '/data.php',
                reader: {
                    type: 'json',
                    root: 'results'
                }
            }

        });
        this.store = store;
        this.callParent(arguments);
    }
});

Ext.onReady(function(){

    var tree = Ext.create('Example', {
        renderTo: Ext.getBody(),
        width: 300,
        height: 300
    });

    tree.getStore().load();
});
Run Code Online (Sandbox Code Playgroud)