Loop through Menu items

Hi,



I am trying to loop through the sub menu items in a menu bar so that I can hide/disable items depending on the user input.



I want to do something like:



children = menu.getItems(parentId)

hideItem(children[1].id)



I can then use a loop to hide all of the items then display the ones I need.



Thanks



Ben

You can use next code
    children = menu.getPanel(parentId).items
    hideItem(children[1].id)

Thanks for your prompt reply, however it didn’t seem to work.

I am using the code below:

aMenuBar=new dhtmlXMenuBarObject(document.getElementById(‘xpstyle’),‘100%’,22,’’);
aMenuBar.setOnClickHandler(onButtonClick);
aMenuBar.setGfxPath(’./include/Menu/img/’);
aMenuBar.loadXML(’./include/Menu/_menu.xml’);
aMenuBar.showBar();    
                
children = aMenuBar.getPanel(‘booking_action’).items;
aMenuBar.hideItem(children[1].id)

The _menu.xml contains:
<?xml version='1.0' ?>

   
            <MenuItem name=“Unbook”  id=“btn_Unbook”/>   
           
               
           
                       
   


And when I run the script I get the error:

children[1] has no properties

Any Ideas



The code is correct problem caused by the timing.
The loading of XML is async., so you need to catch moment when data loaded , it can be done as

aMenuBar.showBar();    
aMenuBar.loadXML(’./include/Menu/_menu.xml’,function(){
    // code here will be called only after xml loading
    children = aMenuBar.getPanel(‘booking_action’).items;
    aMenuBar.hideItem(children[1].id)
});