View Full Version : Dynamic menuitems
mjetpax
10-31-2006, 11:15 AM
I am trying to create a menu with menuitems which are populated based on data with in a dataset, i.e.:
<canvas>
<dataset name="somedata">
<myItem>
<itemName>one</itemName>
<itemXml>myFile.xml</itemXml>
<myItem>
<myItem>
<itemName>two</itemName>
<itemXml>myOther.xml</itemXml>
<myItem>
</dataset>
<menubar>
<menu name="m1" datapath="somedata:/myItem[1]">
<menuitem text="${itemName/text()}" onselect="canvas.whichOne(itemXml/text());"/>
</menu>
</menubar>
</canvas>
The task seems simple enough. Yet, dispite my best efforts, I just can't seem to get it to work properly.
caclark
10-31-2006, 12:29 PM
what is the behavior you expect and what's actually happening?
mjetpax
10-31-2006, 12:48 PM
I would like the code to create a menu with a menuitems for each <myItem> node in the dataset. i.e.
<dataset name="dset">
<myItem>
<itemName>one</itemName>
<itemXml>myFile.xml</itemXml>
<myItem>
<myItem>
<itemName>two</itemName>
<itemXml>myOther.xml</itemXml>
<myItem>
</dataset>
menubar:
~ menu:
menuitem: (1st instance reflects <myItem> node 1 of dset)
~ 1. show itemName as text
~ 2. onselect pass itemXml to some method
menuitem: (2nd instance reflects <myItem> node 2 of dset)
~ 1. show itemName as text
~ 2. onselect pass itemXml to some method
I only get errors. I would be more specific, however, I have tried so many variations of the code at this point, I don't know where to begin.
senshi
10-31-2006, 01:22 PM
Try it this way around. I marked the changes with a bold fontface.
<canvas>
<dataset name="somedata">
<myItem>
<itemName>one</itemName>
<itemXml>myFile.xml</itemXml>
</myItem>
<myItem>
<itemName>two</itemName>
<itemXml>myOther.xml</itemXml>
</myItem>
</dataset>
<menubar>
<menu name="m1">
<menuitem datapath="somedata:/myItem" text="$path{'itemName/text()'}"
onselect="Debug.write(this.datapath.xpathQuery('itemXml/text()'));"/>
</menu>
</menubar>
</canvas>
mjetpax
10-31-2006, 01:45 PM
Wow, senshi you are the master. I can't tell you how many forum posts and documentation pages I have read through on this issue and none of them lead me to a successful conclusion. And there it is, the solution, simple and elegant.
Thanks!
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.