Categories | Question details Back To List | ||
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 Answer posted on May 13, 2008 08:36 You can use next code children = menu.getPanel(parentId).items hideItem(children[1].id) Answer posted by Ben Durber on May 13, 2008 08:59 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' ?> <menu maxItems="12" name="" mixedImages="yes"> <MenuItem name="Action" src="Eng.png" imageSize="24" id="booking_action" disableImage="no" withoutImages="yes" > <MenuItem name="Unbook" id="btn_Unbook"/> <MenuItem name="Terminate" id="btn_Terminate"/> <MenuItem name="Extend" id="btn_Extend"/> <MenuItem name="Temp to Perm" id="btn_TemptoPerm"/> <MenuItem name="Delete" id="btn_Delete"/> </MenuItem> </menu> And when I run the script I get the error: children[1] has no properties Any Ideas Answer posted by Support on May 14, 2008 08:30 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) }); |