return new Ext.Button({
text: cfg.text,
menu: {
xtype: 'menu',
items: cfg.menu,
listeners: {
itemclick: {
fn: function() {
console.log(this);
this.fireEvent('tabchange', 'apps');
},
scope: this
},
scope: this
},
scope: this
},
minWidth: 50,
scope: this
});
cfg comes as a parameter to the function. It's all there. Console.log works - therefor code up until that point works as well. The this does seem to be in the right scope.
Yet the fireEvent ends up with:
Uncaught TypeError: Cannot read property 'apply' of undefined
Following the calls in the error log, fireEvent does get executed, it reaches
EXTUTIL.Event.fire
if(l && l.fireFn.apply(l.scope || me.obj || window, args) === FALSE)
Is where it fails.
Is there some kind of scoping/ nesting issue when trying to call an event inside event listener?
My goal is to trigger that event on a menu item selection for the button.
Apparently it was due to a undefined handler.
The handler was set using
this.on()
in initComponent before superclass init.