使用jstree打开一个节点及其所有父节点 [英] Open one node and all its parents using jstree
本文介绍了使用jstree打开一个节点及其所有父节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用jstree并在打开页面时打开一个节点及其所有父节点.这是我用来测试的html代码.
I'm trying to use jstree and let one node and all its parent be opened when the page is opened. Here is the html code I used to test.
<div id="treeTask">
<ul>
<li id="node_37"><a href="#">TEST1</a>
<ul>
<li id="node_38"><a href="#">TEST2</a></li>
<li id="node_39"><a href="#">TEST3</a></li>
</ul>
</li>
</ul>
<ul>
<li id="node_3"><a href="#">TEST1</a>
<ul>
<li id="node_4"><a href="#">TEST2</a></li>
<li id="node_6"><a href="#">TEST3</a></li>
</ul>
</li>
</ul>
</div>
这是初始化jstree并打开节点的调用.
And here is the call to initialize jstree and open the node.
$(function () {
$("#treeTask").jstree();
$("#treeTask").bind("ready.jstree", function (event, data) {
$("#treeTask").jstree("open_node", $("#node_4"));
if((data.inst._get_parent(data.rslt.obj)).length) {
data.inst._get_parent(data.rslt.obj).open_node(this, false);
}
});
});
我已经处理了一段时间的代码,但无法使其正常工作.如果有人可以提供帮助,我将不胜感激.
I have been manipulating the code for a while, but could not make it work. I would really appreciate if anyone can help.
非常感谢!
推荐答案
您可以使用内置的_open_to
函数:
http://www.jstree.com/api/#/?q= open_to& f = _open_to%28obj%29
You can use the built-in _open_to
function:
http://www.jstree.com/api/#/?q=open_to&f=_open_to%28obj%29
$("#treeTask").jstree().bind('ready.jstree', function (event, data) {
data.instance._open_to('node_4');
});
这篇关于使用jstree打开一个节点及其所有父节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文