dockedItems - 来自Panel的文本

时间:2013-10-21 09:45:41

标签: extjs extjs4 extjs4.1 extjs4.2

我有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(){}。我怎么能在这个函数中看到变量呢?

1 个答案:

答案 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');
    }
});