# Expand the Tree to a specific level

2 answers

This is just a guide, since you didn't provide any sample data or code, but you can use a recursive function to iterate through the tree, stopping when a certain depth is reached. Something like:

```
function expandNode(node, depth) {
// Expand this node
node.setExpanded(true);
// Reduce the depth count
depth--;
// If we need to go deeper
if (depth > 0) {
for (var i = 0; i < node.children.length; i++) {
// Go recursive on child nodes
expandNode(node.children[i], depth);
}
}
}
```

and call it root node and total depth:

`expandNode(rootNode, 5);`

There might be better techniques for iterating fancytree, but I haven't used fancytree before

+1

source to share