Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted on Oct 23, 2009 00:57
open dhtmlx forum
dhtmlxtree.....how to get a list of childs and child childs of a particular node in tree

hi regarding dhtmlxtree.....
how to get a list of childs, child childs, child child childs and so on..... of a particular node in tree?

for example:
Consider tree......
A---B--C---D
B-E-F
E-G

Consider Node B, i need all the child nodes of Node B

i.e. C,D,E,F,G

Answer posted by Alex (support) on Oct 23, 2009 01:24

Hello,

There is the getAllSubItems method. It returns list of all child items:

http://www.dhtmlx.com/dhxdocs/doku.php?id=dhtmlxtree:api_method_dhtmlxtreeobject_getallsubitems

Answer posted on Oct 23, 2009 03:22
thanks for the reply.........
i know this method and i have used this method already............
As you said getAllSubItems method will return list of all child items.............but my requirement is different
Req: consider a node with same text exists at different paths of tree.......now i want the child nodes of a nodes (having same name) which exist at different paths of hierarchy...
Consider tree......
A---B--C---D
B-E-F
E-G

Consider Node B, i need all the child nodes of Node B
Note: here B exists at diffrent places in the tree with childs C,D and E,F
similarly E exists at different places in the tree....with childs F and G

So, finally childs of B are C,D,E,F,G


Answer posted by Alex (support) on Oct 23, 2009 06:12

In this case you need to iterate through all tree nodes and check labels of items:

The getItemText(itemId) method allows to get text of an item.

var list = tree.getAllSubItems(0); /*all items of the tree*/

var items = list.split(",");

for(var i = 0; i < items.length;i++){

/*your code here*/

}