ExtJS多个监听器

Ben*_*ing 4 javascript extjs

我有一个属性网格,我想添加多个"afterrender"监听器.是否可以添加多个相同类型的侦听器,或者在一个侦听器中触发多个函数?

我试过了:

afterrender: function(){...},
function(){...}
Run Code Online (Sandbox Code Playgroud)

但它并没有激发这两个功能.

小智 8

使用相同事件调用多个函数的另一种方法是使用on:

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


Joh*_*ugh 4

只需在函数回调中进行多个函数调用即可。下面显示了一个完整的例子......

工作小提琴

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();
        }
    }
});
Run Code Online (Sandbox Code Playgroud)