Getting all leaf nodes from a sub node in a tree

Hi all,

I know I can use getAllChildless to get me all leaf nodes in a tree, but is it possible for a specific sub node to get the leaf nodes of that sub node?

e.g.

±A
±–B
±----C
±----D
±------E
±–F
±----G

If i said getNode(B).getChildless [<—I know this is made up code]

then it would return C & E, as it would check for nodes under node B that are childless, rather than checking the entire tree.

Is this possible?

Hi
There is no ready approach, bu you can use method getAllSubItems() to get the hole brunch under this node and iterate all the nodes to use method getAllChildless() for them.

i was thinking of doing a getAllChildless to create an array out of then doing

getAllSubItems from the current selected node, then iterating that list and checking if each element is in the getAllChildless array (indexOf)

If they exist in the array then push them to a new array

that new array should now contain all my sub nodes that don’t have children.

Would your suggestion be any more efficient than what I’m suggesting?

Sorry for misleading you…
I meant:
There is no ready approach, bu you can use method getAllSubItems() to get the hole brunch under this node and iterate all the nodes …
for the next:

ch = tree.hasChildren(itemId); if(ch==0){function()}

Hi,

I am confused how your code snippet would work, would you be able to provide more explanation?

Hi
For example i handled boble click to trigger the function:

dhxTree = new dhtmlXTreeObject("mytree", "600px", "600px", 0); dhxTree.setSkin('../dhtmlxTree/codebase/imgs/dhx_skyblue'); dhxTree.setImagePath("../dhtmlxTree/codebase/imgs/csh_bluebooks/"); dhxTree.attachEvent("onDblClick", function(id){ arr = dhxTree.getAllSubItems(id); splited = arr.split(","); for (var i = 0; i < splited.length; i++){ ch = dhxTree.hasChildren(splited[i]); if(ch==0){ dhxTree.setItemColor(splited[i],"red","red") } } }); dhxTree.loadXML("../___xml/tree_unselected.xml", dhxTree.clearSelection("books"));

Darya,

Thank you so much. It works fine everywhere.

You are welcome!