PDA

View Full Version : Ext.menu.Menu's addMenuItem method does not work in Custom Menu class. Is this a bug?



tungchau
26 Feb 2010, 2:25 AM
Hi,
I got a very weird problem. I could not make addMenuItem, or addItem calls to work in my custom Menu class. My custom Menu class is as simple as the following one:


MyMenu = Ext.extend(Ext.menu.Menu, {
initComponent:function(){
//this.addItem(new Ext.menu.Item({text: "Roger"})); //I tried this one too
this.addMenuItem({text: "Roger"});
//this.doLayout() //I tried this one too, it did not help.
//this.items = [{text: "Roger"}]; //THIS ONE WORKS.
MyMenu.superclass.initComponent.apply(this, arguments);
},
afterRender:funciton(){
//this.addItem(new Ext.menu.Item({text: "Roger"})); //I tried this one too
//this.addMenuItem({text: "Roger"});//I tried this one too
//this.doLayout();//tried this one, but it did not help
MyMenu.superclass.afterRender.apply(this, arguments);
}
});


The only way I can make it work is creating Ext.menu.Menu instance without extending the class as the followings:


{
xtype: "button",
text: "Add Stuff",
menu: new Ext.menu.Menu({
items: [
{text: "Roger"}
]
})


Is there anybody having the same problem out there? Was there anything I missed in the first approach? I really need to extend Ext.menu.Menu class badly because I need to generate a menu on the fly based on hierarchical data received from the server. My menu will need to contain sub menu and etc.

This is a very wierd error. I wonder if it is an existing bug. I search the forum and did not see anyone complain about calling addMenuItem in a sub class of Ext.menu.Menu class. I am using 3.1.1 version. Any advice is greatly appreciated.

tungchau
26 Feb 2010, 2:06 PM
Nevermind. I managed to make my menu work by just using this.items=[] inside initComponent.
this.addMenuItem will only work after we call a constructor.