I have a question about using jsTree. I have a functional tree, along with code that displays the text of the selected node. I'm now trying to get the tree to collapse after the node is selected. The problem is that once the tree is closed, a new node is selected. When the new (non-leaf) node is selected, it triggers a new event that wipes out the selection the user just made.
Here's the code from the ready() function:
- $('#products')
- .bind("select_node.jstree", function (event, data){
- // alert("selected " + data.inst.get_text(data.rslt.obj));
- // Don't let non-leaf nodes be selected
- if ( /*event.type == "select_node" &&*/ data.inst.is_leaf() == false)
- {
- $( "#treeSelection").html( "");
- event.stopImmediatePropagation();
- return false;
- }
- $( "#treeSelection").html( data.inst.get_text(data.rslt.obj));
- // Now close the tree
- var foo = $( "#products");
- $( "#products").jstree('close_all', -1);
- });
Is there some way I can programmatically select the root of the tree before doing the close_all, or is there a better approach? Thanks.