1. #1
    Ext User
    Join Date
    Feb 2008
    Posts
    10
    Vote Rating
    0
    villinz is on a distinguished road

      0  

    Red face How to add a submenu to a menu item dynamicly?

    How to add a submenu to a menu item dynamicly?


    Just like the title, I want to add a submenu to a menu item dynamicly, but I can't find a method like "addMenu" or "addItem" in the Ext.menu.Item apis.
    How to do it?
    my extjs version is "2.0.2".
    thanks! any response will be appreciated.

  2. #2
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,353
    Vote Rating
    78
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    menu items are the last stop for a menu. You'll need to add menu's to your menu in order to add stuff to child nodes.

  3. #3
    Sencha User
    Join Date
    Jan 2008
    Posts
    5
    Vote Rating
    0
    trekmbikes is on a distinguished road

      0  

    Default


    Could you post some sample code for this? I'm having trouble creating a nested set of menus. Thanks!

  4. #4
    Sencha User
    Join Date
    Jan 2008
    Posts
    5
    Vote Rating
    0
    trekmbikes is on a distinguished road

      0  

    Default


    Nevermind, found it!

    I was looking for the "menu" config property of the "Item" class. Since this is only settable at object creation time (and not later through a method), I suppose it's an implied requirement that the submenus are built before the parent menu.

    For those who may be interested:
    I have a Java tree structure (represented as a map of maps). I serialize it using Jabsorb/JSON-RPC, then create extjs menus (& submenus) using the following javascript method:

    Code:
    function buildMenu(theMenu, theTree) {
    		for (var i in theTree) {
    			var subMenu = null
    			if (theTree[i].map) {
    				subMenu = new Ext.menu.Menu({
    				    ignoreParentClicks : true
    				})
    				buildSuggestionMenu(subMenu, theTree[i].map)
    			}
    			
    			var newItem = {
    				text: i
    			}
    			if (subMenu != null)
    				newItem.menu = subMenu
    			
    			theMenu.add(newItem)
    		}
    	}