简体   繁体   English

向ExtJS gridPanel按钮的处理程序添加多个功能

[英]adding multiple functions to an ExtJS gridPanel button's handler

I have an ExtJS gridPanel with a button that fires a global function: 我有一个带有触发全局函数的按钮的ExtJS gridPanel:

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

After I have called the group function, I need to call another global function, for instance renameGroups ; 在调用了group函数之后,我需要调用另一个全局函数,例如renameGroups how do I place this function, or indeed any additional functions, in the handler? 如何在处理程序中放置此函数或实际上任何其他函数?

What we do in JavaScript usually is define our own function calling all the others, so in your example: 我们在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);
        }
    }
]
...
});

There are a few different options. 有几种不同的选择。

  1. Instead of using a handler, you could listen for click from another component. 无需使用处理程序,您可以侦听来自其他组件的点击。 For example: 例如:

    grid.down('[text=Group]').on('click', function() {}); grid.down('[text = Group]')。on('click',function(){});

  2. You can put a function in the grid and call it directly from inside the handler: 您可以在网格中放置一个函数,然后直接从处理程序内部调用它:

    button.up('grid').renameGroups(); button.up( '网格')renameGroups();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM