单击节点时打开分支? [英] Open branch when clicking on a node?
问题描述
我在这里遇到了 jsTree 。到目前为止,它可以工作,我可以使用[+]图标浏览和扩展节点,并在单击节点时打开页面,但我还是希望它在有人点击某个节点时展开所有直接节点。
I'm stuck with jsTree here. So far it works and i can browse and expand nodes with the [+] icon and open pages when clicking a node, BUT i still want it to expand all the immediate nodes whenever someone clicks on a node.
我看了一下至少2个小时但是找不到任何东西。官方网站不是很有帮助,因为他们没有足够的例子,而且没有很好的记录。看看这个,但对我来说也不起作用:
http://luban.danse.us/jazzclub/javascripts/jquery/jsTree/reference/_examples/2_operations.html
i had a look at around for at least 2 hours but couln't find anything. the official website is not very helpfull because they don't have enough examples, and its not very well documented. had a look at this one, but didn't work for me either: http://luban.danse.us/jazzclub/javascripts/jquery/jsTree/reference/_examples/2_operations.html
我甚至没有在firebug中收到错误消息
i didn't even get an error message in firebug
所以这里是我的代码现在的样子,
tree init:
so here is how my code looks right now, tree init:
$(function () {
$("#jstree").jstree({
....
点击节点触发的功能
.delegate("a","click", function (e) {
//click on node
var page_id = $(this).parent().attr("page_id");
var idn = $(this).parent().attr("id").split("_")[1];
/*
dosnt seem to work either...
$(this).jstree("openNode", $("#node_"+idn));
$(this).jstree("openNode", "#node_"+idn);
*/
page = "index.php?page_id="+page_id;
//location.href = page;
})
.bind也没有工作:
.bind didnt work either:
$(this).bind("open_node.jstree", function (event, data) {
if((data.inst._get_parent(data.rslt.obj)).length) {
data.inst._get_parent(data.rslt.obj).open_node(this, false);
}
})
有人看到我在这里缺少的东西......?
does anyone see what i'm missing here...?
推荐答案
你需要绑定到select_node.jstree并在触发时调用树实例上的toggle_node:
You need to bind to select_node.jstree and call toggle_node on the tree instance when it's triggered:
对于jsTree版本< 3.0:
For jsTree versions < 3.0:
$("#your_tree").bind("select_node.jstree", function(event, data) {
// data.inst is the tree object, and data.rslt.obj is the node
return data.inst.toggle_node(data.rslt.obj);
});
对于jsTree版本> = 3.0
For jsTree versions >= 3.0
$("#your_tree").bind("select_node.jstree", function (e, data) {
return data.instance.toggle_node(data.node);
});
这篇关于单击节点时打开分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!