开发者

Calling functions with click handlers in ExtJS 4

开发者 https://www.devze.com 2023-03-27 07:38 出处:网络
I have a function inside a toolbar, let\'s call it: Ext.define(\'MyArchive.Toolbar\', { search: function() {

I have a function inside a toolbar, let's call it:

Ext.define('MyArchive.Toolbar', { 
  search: function() {
    console.log('searching');
  }
}

Now I'd like to call this function when clicking a button. So I'm adding some click handlers in the afterRender on the toolbar setup:

afterRender: function() {
  Ext.getCmp('search-button').on('click', this.search);
} 

However, this doesn't work and I ultimately need to go the full route of:

afterRender: function() {
  Ext.getCmp('search-button').o开发者_JAVA百科n('click', function() {
    quick_search();
  )};
}

Any particular reason why my first attempt doesn't apply the click handler as I expect?

Thanks for any explanations or refactorings! Additional patterns/idioms welcome...


Next try:

    var panelOverall = new Ext.form.FormPanel({
    html: 'bla',
    search: function() {
        console.log('searching');
    },
    buttons: [
        {
            text: 'Moo',
            id: 'button1',
            handler: function(){
                //window.destroy();
            }
        }
    ],
    afterRender: function() {
        Ext.getCmp('button1').on('click', this.search);
    } 
});

is working for me.. am I missing something?

0

精彩评论

暂无评论...
验证码 换一张
取 消