微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Extjs 4.2.1 – config autoLoad:false失败

我定义了一个treepanel扩展扩展:’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
    }] 
})

如何解决这个问题.

您必须重写Ext.tree.Panel.setRootNode metod以考虑商店的autoLoad属性.

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

Ext.define('Example',/**
     * Override.
     */
    setRootNode: function() {
        if (this.getStore().autoLoad) {
            this.callParent(arguments);
        }
    },proxy: {
                type: 'ajax',url: '/data.PHP',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();
});

原文地址:https://www.jb51.cc/php/137454.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐