我有Tree面板。
一切正常!
Ext.define('My.Tree', {
extend:'Ext.tree.Panel',
id: 'DriveTree',
store: storeTree,
ChooseButtonText: 'ChooseFolder',
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'BUTTON TEXT', // this.ChooseButtonText
id:'connectButton',
handler: function(){
alert(this.ChooseButtonText);
}
},
]
}],
});
Ext.onReady(function(){
var tree =Ext.create('My.Tree', {});
});
但是dockedItems的文本想要来自Panel。像这样的东西:
text:this.ChooseButtonText
每个dockedItems都有listener - handler:function(){}。我怎么能在这个函数中看到变量呢?
答案 0 :(得分:3)
在initComponent中执行:
Ext.define('My.Tree', {
extend: 'Ext.tree.Panel',
id: 'DriveTree',
store: storeTree,
ChooseButtonText: 'ChooseFolder',
initComponent: function() {
this.dockedItems = [{
xtype: 'toolbar',
items: [{
text: this.ChooseButtonText,
scope: this,
handler: this.onConnectButtonClick
}]
}];
this.callParent();
},
onConnectButtonClick: function() {
console.log('Do something');
}
});