Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Page on Apr 07, 2008 08:07
open dhtmlx forum
Problem Dynamically Adding Submenu

I'm trying to follow the Mixed Initialization example with little success. I would like to add submenu items in script after loading the original menus from XML.

<script>

helpMenuBar = new dhtmlXMenuBarObject('helpMenu','100%',40,"");
helpMenuBar.setOnClickHandler(selectMenu);
helpMenuBar.setGfxPath("../dhtmlxMenu/codebase/imgs/");
helpMenuBar.loadXML("helpMenu.xml");
helpMenuBar.showBar();

var subMenu = helpMenuBar.getPanel("legend");
var pItem = new dhtmlXMenuItemObject("_Programs","Programs",null,null,"");
helpMenuBar.addItem(subMenu,pItem);

</script>

XML file:

<?xml version='1.0' encoding='iso-8859-1'?>
<menu width="100%" height="40" menuAlign="center">
<MenuItem name="Help" id="help">
<MenuItem name="Legend" id="legend"/>
<MenuItem name="About" id="about"/>
</MenuItem>
</menu>

Thank again for a great product!



Answer posted by Support on Apr 07, 2008 10:01
The XML loading is async, so you need to call additional code only after xml loaded

helpMenuBar.loadXML("helpMenu.xml",function(){
    var subMenu = helpMenuBar.getPanel("legend");
    var pItem = new dhtmlXMenuItemObject("_Programs","Programs",null,null,"");
    helpMenuBar.addItem(subMenu,pItem);
});
helpMenuBar.showBar();


Answer posted by Page on Apr 07, 2008 12:18
That worked great, thanks!

How can I  add an item to an existing submenu? The code above appends the item after the last existing item.
Answer posted by Support on Apr 08, 2008 02:37
>>How can I  add an item to an existing submenu?
By using panel parameter you specified to which panel item will be added.

>>The code above appends the item after the last existing item.
addItem command adds new element to the end of pannel, the API doesn't allow to add new element is specific place.
Answer posted by Page on Apr 08, 2008 09:17
Thanks. I decided to just go ahead and build the entire menu from script. It worked well. Thanks for the great support.