userData : I wish I could do this

I’ve searched, and it looks like this doesn’t exist:



In certain cases, I’d like to put complex data into userdata.



In one example, I have a dhtmlx menu, which is loaded from XML.



the function which handles the onClick event for my menu… pulls several values (from userdata) and stores them in clientside variables.



So my xml looks something like this:





VLD

Contacts

Contacts and Leads

All





VLD

Projects

Potential Projects

Potentials_All







The problem, is that the number of variables passed will change.

I really need to LOOP through the userdata on the client side, and get the “name”=>“value” of each userdata in the collection.



Another usefull option would be to use xml within userdata, something like:





value1

value2





And then the ability to turn the userdata contents into an xml object.



Am I missing something?



i have no problems setting and getting userdata…but I don’t have a method for looping through all userdata.



There is no public method to achieve such functionality, but the next code can be used

var el = tree._idpull[ID];
var data = el._userdatalist.split(",");
for (var i=0; i<data; i++)
alert(data[i] + " = " + tree.getUserData(data[i]));

Thanks for that… but in my case, I’m trying to use with a dhtmlxMenu…
My menu is attached to a dhtmlxLayout (obj: parent_layout)

main_menu = parent_layout.attachMenu();
main_menu.setImagePath(dhtmlx_imagePath);
main_menu.loadXML("_menuHandlers/MainMenu.php");
main_menu.attachEvent(“onClick”, function(id, zoneId, casState){main_menu_handler(id);});

The following code doesn’t work for me:

function main_menu_handler(btnID){
     
         var el = main_menu._idpull[btnID];
         var data = el._userdatalist.split(",");
         for (var i=0; i<data; i++)
        alert(data[i] + " = " + main_menu.getUserData(data[i]));
}


Hello,


this approach was recommended for dhtmlxtree. Unfortunately it can not be applied to dhtmlxmenu.


Userdata is stored in the userData array as follows


menu.userData[menu.idPrefix+itemId+"_"+name] = value;

Thanks again! 

Here is the quick little function I wrote which gets all the userdata items for a the menu button which was clicked:

 function main_menu_handler(btnID){
         var msgStr="";
         var varStrArr;
         var theData = main_menu.userData;
         for (keyStr in theData){
            varStrArr = keyStr.split(btnID+"_");
            if (varStrArr[1]) {
                  msgStr=msgStr+varStrArr[1]+"=>"+theData[keyStr]+"\n";
            }
         }
         alert (msgStr);

}