7

我定义了一个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);
    }
 });

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

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

                root: {
                    text: 'Ext JS',
                    id: 'src',
                    expanded: false // this 
                }

root如果不使用类似的配置,我的 json 很好并且可以工作

({  "results": [
    { 
        id : '1' , 
        text : '1', 
        expanded: true, 
        results :[{ 
            id : '2' , 
            text : '2', 
            leaf:true
        }]
    },{ 
        id : '3' , 
        text : '3', 
        leaf:true
    }] 
})

怎么解决谢谢。

4

3 回答 3

5

您必须覆盖Ext.tree.Panel.setRootNodemetod 才能考虑到商店的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();
});
于 2013-10-14T23:31:14.170 回答
4

我不知道为什么“自动加载:假;” 不起作用。但是您可以通过在 treepanel 中添加“root”配置来防止自动加载。不在树店里。并且load()也可以正常工作。

{
    xtype: 'treepanel',

    .....

    root: {
        loaded: true;
    }
}

这会奏效。

var myTreeStore = Ext.create('Ext.data.TreeStore', {
    fields: [ ... ],

    proxy: { ... },

    root: {
        loaded: true;
    }
});

这行不通。

祝你好运。

于 2014-06-18T05:47:47.697 回答
0

老实说,您可能只是在寻找 queryMode: 'local',我不是 100% 它适用于此,但这就是我会做的..

我一直在组合框上使用它,它强制本地存储管理(关闭自动加载)

于 2014-06-02T21:57:35.500 回答