在Extjs 4.2.2 中构建一个treePanel 发现设置rootVisible后 ,treeStore中设置的autoLoad:false不启作用,在组件初始化的时候即加载数据源,造成数据重复加载,google 发现了一个解决方法,记录一下
Ext.define('Example', {
extend: 'Ext.tree.Panel',
title: 'Example',
useArrows:false,
singleExpand : true,
rootVisible: false,
border: false,
listeners : {
itemcontextmenu : {
fn : configAndDelete
},
beforeitemexpand : {
fn : function(record,eOpts){
var self = this;
var proxy = self.getStore().getProxy();
proxy.extraParams.symbol = activeSymbol;
}
}
},
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();
});