单击节点时打开分支?

2024-04-02

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

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

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


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

对于 jsTree 版本

$("#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);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

单击节点时打开分支? 的相关文章

随机推荐