PDA

View Full Version : [3.0rc1.1] Submenu doesn't show up



MartiCode
7 May 2009, 9:53 AM
I found this issue with using context menu with submenu : the submenu appears the first time, but not a second time around. I don't recall facing this with 2.2.

<button id="mybutton">Click me and again</button>

<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();

Ext.get('mybutton').on('click', function (e) {

var contextMenu = new Ext.menu.Menu({
items: [{
text: 'Priority',
menu: {
items:[{
id: 'priority-2',
text: 'High'
},{
id: 'priority-1',
text: 'Normal'
},{
id: 'priority-0',
text: 'Low'
}]
}
}]
});
contextMenu.showAt(e.xy);

});

});
</script>

Animal
7 May 2009, 9:57 AM
You create a new context menu on every click of your button? Not good is it?

Of course subsequent, completely new context menus won't work because the id of a Component must be unique, and there are already Components rendered with those three 'priority-n' ids.

Please post in "Help".

MartiCode
7 May 2009, 10:15 AM
Makes sense now. The odd thing is, I didn't notice this behavior with 2.2, so that's why I assumed the problem wasn't in my code.

So I suppose I have to manually unregister that menu after it's done being displayed ?

Animal
7 May 2009, 10:19 AM
Don't create multiple ones. Just create one. When needed.

Animal
7 May 2009, 10:20 AM
Prior to 3.0 an Ext.menu.Menu was not an Ext.Container housing Ext.Components. It was a class out on its own.

MartiCode
7 May 2009, 12:08 PM
Don't create multiple ones. Just create one. When needed.
Thanks, I guess I'll cache the menu somewhere then.

enpasos
12 Jun 2009, 9:33 AM
What if the contextmenu is strongly context sensitive and you therefore want to throw it away after use and create a new (and likely different) one when needed?

MartiCode
12 Jun 2009, 10:40 AM
What if the contextmenu is strongly context sensitive and you therefore want to throw it away after use and create a new (and likely different) one when needed?
What I do is keep a menu component around and just populate it in "beforeshow" event depending on context.

Animal
12 Jun 2009, 11:39 PM
Or create one for each context.