Javascript 将多个函数添加到ExtJS gridPanel按钮';s处理程序

Javascript 将多个函数添加到ExtJS gridPanel按钮';s处理程序,javascript,extjs,Javascript,Extjs,我有一个ExtJS gridPanel,带有一个触发全局函数的按钮: grid = Ext.create('Ext.grid.Panel', { ... tbar: [ { xtype: 'button', text: 'Group', handler: group // call to global function } ] ... }); 调用组函数后,我需要调用另一个全

我有一个ExtJS gridPanel,带有一个触发全局函数的按钮:

grid = Ext.create('Ext.grid.Panel', {
...
    tbar: [
        {
            xtype: 'button',
            text: 'Group',
            handler: group // call to global function
        }
    ]
...
});

调用
函数后,我需要调用另一个全局函数,例如
重命名组
;如何在处理程序中放置此函数或任何其他函数?

我们在JavaScript中所做的通常是定义我们自己的函数调用所有其他函数,因此在您的示例中:

grid = Ext.create('Ext.grid.Panel', {
...
tbar: [
    {
        xtype: 'button',
        text: 'Group',
        // will call the function when clicked, which will then call the others
        handler: function(e) {
            group(e); 
            renameGroups(e);
        }
    }
]
...
});

有几种不同的选择

  • 您可以侦听来自另一个组件的单击,而不是使用处理程序。例如:

    grid = Ext.create('Ext.grid.Panel', {
    ...
    tbar: [
        {
            xtype: 'button',
            text: 'Group',
            // will call the function when clicked, which will then call the others
            handler: function(e) {
                group(e); 
                renameGroups(e);
            }
        }
    ]
    ...
    });
    
    grid.down('[text=Group]')。on('click',function(){})

  • 您可以将函数放入网格中,并直接从处理程序内部调用它:

    button.up('grid')。重命名组()


  • 感谢您的回答,以及相关的代码示例,这很容易理解。