gpt4 book ai didi

javascript - 单击节点时打开分支?

转载 作者:行者123 更新时间:2023-12-03 21:35:56 25 4
gpt4 key购买 nike

我被 jsTree 困住了这里。到目前为止,它可以工作,我可以使用 [+] 图标浏览和展开节点,并在单击节点时打开页面,但我仍然希望它在有人单击节点时展开所有直接节点。

我环视了至少两个小时,但什么也没找到。官方网站不是很有帮助,因为他们没有足够的示例,并且没有很好的记录。看过这个,但对我来说也不起作用: http://luban.danse.us/jazzclub/javascripts/jquery/jsTree/reference/_examples/2_operations.html

我什至没有在 firebug 中收到错误消息

这是我的代码现在的样子,树初始化:

$(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 也不起作用:

$(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);
}
})

有人看到我在这里缺少什么吗......?

最佳答案

您需要绑定(bind)到 select_node.jstree 并在触发时在树实例上调用toggle_node:

对于 jsTree 版本<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

$("#your_tree").bind("select_node.jstree", function (e, data) {
return data.instance.toggle_node(data.node);
});

关于javascript - 单击节点时打开分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4486032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com