Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS multiple listeners

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.

like image 277
Ben Irving Avatar asked Dec 14 '22 13:12

Ben Irving


2 Answers

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);
}
like image 179
Hernan Payrumani Avatar answered Dec 25 '22 05:12

Hernan Payrumani


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();
        }
    }
});
like image 22
John Tough Avatar answered Dec 25 '22 04:12

John Tough