Categories | Question details Back To List | ||
How to set attributes to the nodes in Tree Hi, This is in continuation with the question I asked previouslyindex.php?s=normal&q=2260&a=2847 index.php?s=normal&q=2260&a=2847 The method to get the attribute values is working fine. { tree._idpull[tree.getSelectedItemId()].attrs["im0"] } When I use my application to add a new node to my tree I want to set certain extra attributes (along with there values), similar to the way we set im0, im1 and im2 (the icons for the nodes), how to achieve this. Something like tree.setAttribute( id, "attrName", "attValue"); This will help me set any number of attributes to any selected node of the tree. This is how I am adding node in my tree tree.insertNewItem(tree.getSelectedItemId(),0,document.getElementById('newGroupNameTxt').value,0,"folderClosed.gif","folderOpen.gif","folderClosed.gif",'SELECT'); Also the structure of my XML looks like this <item text="Brakes" id="0" isGroup="1" im0="folderClosed.gif" im1="folderOpen.gif" im2="folderClosed.gif"> <item text="Rear disc brake" id="Rear_disc_brake" isGroup="0" im0="leaf.gif" im1="leaves.gif" im2="leaf.gif" attr1="1" attr2="2" attr3="3"/> <item text="ABS" id="ABS" isGroup="0" im0="leaf.gif" im1="leaves.gif" im2="leaf.gif" attr1="1" attr2="2" attr3="3"/> <item text="Emergency brake assist" id="Emergency_brake_assist" isGroup="0" im0="leaf.gif" im1="leaves.gif" im2="leaf.gif" attr1="1" attr2="2" attr3="3"/> <item text="Ceramic brake" id="Ceramic_brake" isGroup="0" im0="leaf.gif" im1="leaves.gif" im2="leaf.gif" attr1="1" attr2="2" attr3="3"/> </item> Thanks -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Answer posted by Support on Mar 13, 2008 02:11 There is no built in support for such custom attributes, but in case of your code modification, next solution can be used var newItem=tree.insertNewItem(tree.getSelectedItemId(),0,document.getElementById( newItem.attrs[name]=value; In common case the same effect can be achieved by tree._idpull[ID].attrs[name]=value; By the way, syntax of your insertNewItem command is not correct, the second parameter of command must be an ID of item, which must be unique value - you are using 0, which is not valid here. |