Open branch when clicking on a node?

冷暖自知 提交于 2019-12-02 20:22:24

You need to bind to select_node.jstree and call toggle_node on the tree instance when it's triggered:

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

For jsTree versions >= 3.0

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

With a newer version of jsTree (3.0.0 according to jsTree.js), i had to change the code provided by @justind a bit to work:

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

I use this (casoUso is the page linked, fInvocaCasoUso is a function to make the call).

  $("#demo1").bind("select_node.jstree", function (e, data)
                    {
                        if (data.rslt.obj.attr("casoUso")!=undefined)
                        {
                            fInvocaCasoUso(data.rslt.obj.attr("casoUso"));
                        }
                        else
                        {
                            $("#demo1").jstree("toggle_node",data.rslt.obj);
                        }
                    });

If the node has a link, it opens, if not, the sub-tree is opened. Anyway, you should be able to combine both sides of "if" to open the branch and execute your link. Maybe executing:

       $("#demo1").jstree("toggle_node",data.rslt.obj);
       fInvocaCasoUso(data.rslt.obj.attr("casoUso"));

Would do it...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!