ExtJS multiple listeners

半世苍凉 提交于 2020-01-03 15:56:07

问题


I have a property grid that I want to add multiple "afterrender" listeners to. Is it possible to add multiple listeners of the same type, or fire multiple functions within one listener?

I've tried:

afterrender: function(){...},
function(){...}

but it does not fire both of the functions.


回答1:


Just make multiple function calls within the function callback. Below shows a full example of this...

Working Fiddle

Ext.create('Ext.grid.property.Grid', {
    title: 'Properties Grid',
    width: 300,
    renderTo: Ext.getBody(),

    functionOne: function() {
        alert("functionOne called");
    },

    functionTwo: function() {
        alert("functionTwo called");
    },

    listeners: {
        afterrender: function() {
            var me = this;
            me.functionOne();
            me.functionTwo();
        }
    }
});



回答2:


Another way to call multiple functions with the same event is by using on:

...
initComponent: function () {
  var me = this;
  me.on('afterrender', me.functionA);
  me.on('afterrender', me.functionB);
  ...
  me.on('afterrender', me.functionN);
  me.callParent(arguments);
}



回答3:


yes it is possible. you can add it with "addListener" function.




回答4:


You can do it by calling several functions in a callback function with its all arguments, like this:

afterrender: function() {
    Foo.apply(this, arguments);
    Bar.apply(this, arguments);
}

Now you can define functions Foo and Bar and it would be called with all afterrender callback function arguments.



来源:https://stackoverflow.com/questions/31179396/extjs-multiple-listeners

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!