单击jstree节点,以该节点为根重建树 [英] Click on jstree node, rebuild tree with that node as the root
问题描述
我认为这个主题很明确. :)
I think the subject is reasonably clear. :)
我是jstree新手,并尝试解析文档,但是我越来越 有点卡在这一个.我有以下代码:
I'm a jstree newbie and have tried to parse the docs, but I'm getting a bit stuck with this one. 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
});
该树加载并显示得很好,但是当我单击该节点时 我想成为显示的树的新根,我得到了一个 在标记为FIXME的行出现错误.我尝试过各种方法 没什么好高兴的,真的很感谢您的帮助.我在做什么错了?
The tree loads and displays just fine, but when I click on the node that I want to become the new root of the displayed tree, I get an error at the line marked FIXME. I've tried all kinds of things with no joy, and would really appreciate some help. What am I doing wrong?
推荐答案
如果需要刷新整个树,则可以引用和刷新树的容器.
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!");
});
如果仅需要在select_node中引用该节点: data.rslt.obj [0];
If just the node needs to be referenced in select_node: data.rslt.obj[0];
或者关于获取它的另一轮方法(与上面相同的节点): $ .jstree._reference(data.inst.get_container()).get_selected();
Or another round about way to get it (same node as above): $.jstree._reference(data.inst.get_container()).get_selected();
您可能还需要销毁并重建树: $ .jstree._reference(#tree").destroy(); 我知道这似乎很浪费,但是您还是要替换根节点.
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.
这篇关于单击jstree节点,以该节点为根重建树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!