How to select last node of dhtmlxTree

Hi,



I have menu created using a Accordian, inside accordian i have created a Tree, my issue is:



when i reach to that page, then Accordian 1 should get open ( this i have done using menuAccordian.cells(‘id’).open()), inside Accordian 1 - Tree’s first node should get open (it is also happening automatically), iam not able to check here is - if first node is having child - i should able to reach to last leaf and that leaf should get selected.



How can i able to traverse a Tree and reach to a last leaf of a node



like :



- TREE

- Node 1

- Node 1_1 ( i want this to be selected)

- Node 2



I am using these commands but iam not getting any result:

tree.selectItem(‘1_1’);

tree.openItem(‘1_1’);

tree.focusItem(‘1_1’);



Looking forward for your solutions,





Regards,

Ram


Hello


When do you call this approach ?


The possioble reason for the problem that the provided snippet is called before tree is completely loaded.


Try to call it after xml loading:


tree.loadXML(“some.xml”,function(){


tree.selectItem(‘1_1’);
tree.openItem(‘1_1’);
tree.focusItem(‘1_1’);



)


If you want to get the last leaf using tree API, something as follows can be used:


var list = tree.getAllSubItems(itemId);


var arr = list.splt(",");


var id = arr[arr.length-1];

Thanks , i got the solution it’s working with your example.

Thank you,

Ram