Click on jstree node, restore the tree using node as root

I think the subject is clear enough. :)

I'm new to jstree and trying to parse the docs, but I'm getting a little stuck with this. I have the following code:

$("#tree").jstree({
   "json_data" : {
       "data" : [
           tree.company
       ]
   },
   "themes" : {
       "theme" : "smb",
       "dots" : false,
       "icons" : true
   },
   "plugins" : [ "themes", "json_data", "ui" ]
}).bind("select_node.jstree", function (event, data) {
   $('#tree').jstree.refresh(data.inst.get_selected());  // FIXME
});

The tree loads and displays just fine, but when I click on node that I want to become the new root of the displayed tree, I get an error on the line labeled FIXME. I tried all kinds of things with the help of no joy, and I would really appreciate help. What am I doing wrong?

+3
source share
2 answers

If you need to update the entire tree, then you can specify and update the tree container.

.bind("select_node.jstree", function (event, data) {
    $.jstree._reference(data.inst.get_container()).refresh(); //(data.inst.get_selected());  // FIXME
}).bind("refresh.jstree", function (event, data) {
    alert("Refreshed!");
});

If select_node needs to specify only node: data.rslt.obj [0];

, ( node, ):   $.jstree._reference (data.inst.get_container()) get_selected();.

:  $.jstree._reference ( "# " ) (). , , node.

+2

, , , , :

$('#tree').jstree.refresh(data.inst.get_selected());

:

$('#tree').jstree("refresh", data.inst.get_selected());
+3

All Articles