0

I have three nodes in the tree and would like to keep the first node expanded, is there a way in dojo tree which would support this?

Thanks.

user1716006
  • 51
  • 4
  • 11

2 Answers2

3

If you have id of the node that you want to expand. you can expand that node as follows - myTree will be your tree and expandNodeId is the id of the node you want to expand.

var nodes = myTree.getNodesByItem(expandNodeId);

if(!nodes[0].isExpanded){
     myTree._expandNode(nodes[0]);
}
Swapnil
  • 247
  • 1
  • 7
  • What is "expandedNodeId" supposed to be? Is it branch node or leaf node? – user1739825 Jan 24 '14 at 08:52
  • It is id of the node's data item. tree example here -https://dojotoolkit.org/reference-guide/1.10/dijit/Tree.html has a node named "The earth", id for that node is "world". – Swapnil Sep 20 '16 at 18:05
0

In the above case the expandNodeId is the ID that you assigned to the node that was clicked. So, in your onClick() function you can do something like this;

            var theTree = new Tree({
                model: myModel,
                onClick: function(item, node){

                    // auto-expand the node when clicked
                    var nodes = that.theTree.getNodesByItem(item.id);
                    if(!nodes[0].isExpanded)
                        theTree._expandNode(nodes[0]);

                }
            });
Capstan
  • 71
  • 1
  • 5