PDA

View Full Version : Create menu structure in controller



Cine
5 Jan 2012, 2:58 AM
I am having some problems with figuring out how to populate a menu in the controller.

In my view, in initComponent, I create the menu like this:


me.items = [new Ext.menu.Menu({
id: 'myMenu',
items: []
})];

and then in the controller I would like to be able to do something like:


init: function () {
var me = this;
me.control({
'#myMenu': { created: me.createMenuStructure }
});
me.callParent();
},
createMenuStructure: function () {
debugger;
var menu = [];
menu.push(Ext.create('blablabla', { app: this.application }));
this.items = menu;
}


I have confirmed that
Ext.ComponentQuery.query("#myMenu") returns the object, so that part should work. However, I have tried a ton of different event names, and nothing is working for me "created, added, beforeadd, enable". Debugger never breaks.

It is probably something trivial since I am still learning Ext, but I cant see it.

twaindev
5 Jan 2012, 3:09 AM
Did you perhaps mix up 'myMenu' and 'startMenu'?

And I would use one of the 'render' events.

Cine
5 Jan 2012, 3:26 AM
And I would use one of the 'render' events.

That works. However, "this" is the controller and "arguments" is empty. Do I also need to make a refs for it, seems a bit double work?

Cine
5 Jan 2012, 3:35 AM
And
this.getStartMenu().items = menu; does not work. I end up with an exception from
ContextItem.
Do I have to do it from a store instead? (Anyone know of an example to do that?)

Cine
5 Jan 2012, 3:43 AM
I figured it out.



var menu = this.getStartMenu();
menu.add(...);
return true;

twaindev
5 Jan 2012, 3:45 AM
Great!

For a menu loaded from a store you can look here (http://www.sencha.com/forum/showthread.php?132422-Ext.ux.menu.DynamicMenu-for-ExtJS-4.0).