Click on jstree node, rebuild tree with that node as the root

♀尐吖头ヾ 提交于 2019-12-05 17:12:34

If the entire tree needs to be refreshed, then the tree's container can be referenced and refreshed.

.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 just the node needs to be referenced in select_node: data.rslt.obj[0];

Or another round about way to get it (same node as above): $.jstree._reference(data.inst.get_container()).get_selected();

You may also need to destroy and rebuild the tree: $.jstree._reference("#tree").destroy(); I know this may seem wasteful, but you are replacing the root node anyways.

I'm pretty sure the reason you're getting the error on that line is because you've got your syntax a little off in this line:

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

Try this instead:

$('#tree').jstree("refresh", data.inst.get_selected());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!