PDA

View Full Version : Controller Refs Selector Problem 2



umr.ashrf
4 Sep 2012, 6:35 AM
I have a view and a controller. The view has menu under button of which items when clicked will be handled by controller. The event is never caught by controller if I put class selector but it works if I remove class selector.

Have a look at my code.



Ext.create('Ext.Button', {
text: 'Add Tab',
cls: 'button',
menu: Ext.create('Ext.menu.Menu', {
cls: 'addMenu',
items: [{
text: 'One'
}, {
text: 'Two'
}]
})
});





Ext.define('MyApp.controller.TabController', {
extend : 'Ext.app.Controller',

init : function() {
this.control({
'menu[cls=addMenu]' : {
'click' : this.addTab
}
});
},

addTab : function(a, b, c, d) {
console.log(a, b, c, d);
}
});


What am I doing wrong here?

mitchellsimoens
17 Sep 2012, 6:42 AM
Just from that it should work no issue. Have you tried to resolve it in the console using Ext.ComponentQuery.query?

HriBB
9 Jul 2013, 12:29 PM
I have the same problem. I think it's a bug. It seems that cls property is null after menu is created/shown. So if you overwrite cls property after menu is shown, control ref works ... at least for me :)

View

onContextMenu: function(grid, td, cellIndex, record, tr, rowIndex, e) {
if (!this.contextMenu) {
this.contextMenu = Ext.create('Ext.menu.Menu', {
cls: 'view-name-cmenu',
items: [{
text: 'remove',
cls: 'remove'
}]
});
}
this.contextMenu.showAt(e.getXY());
this.contextMenu.cls = 'view-name-cmenu';
e.stopEvent();
return false;
}

Controller

this.control({
'menu[cls~="view-name-cmenu"] menuitem[cls="remove"]': {
click: this.onMenuItemClick
}
});