如何在jsTree中双击自定义行为?

Gid*_*sey 21 jquery double-click mouseevent jstree

我正在使用jsTree jQuery插件,并希望在用户双击节点时执行代码.

我似乎无法让它发挥作用.我发现了一些关于某个ondblclk事件的文档,但它没有触发.

    browser.jstree(
            {
                plugins: ["themes", "json_data", "ui", "cookies"],
                callback:
                {
                    ondblclk: function (node, tree) {
                        if (!thisReportBrowserthis._isFoldersOnly) {
                            var f = node;
                        }
                    }
                }
            }
        );
Run Code Online (Sandbox Code Playgroud)

如何使用jstree处理双击事件?

Gid*_*sey 24

事实证明我可以做到这一点:

jstree.bind("dblclick.jstree", function (event) {
   var node = $(event.target).closest("li");
   var data = node.data("jstree");
   // Do my action
});
Run Code Online (Sandbox Code Playgroud)

node包含li被点击的内容,并data包含包含我的信息的元数据.


par*_*2eu 6

最后一个版本jsTree 1.0中不存在'dblclick.jstree'.

DoubleClick for node:

$("#yourtree").delegate("a","dblclick", function(e) {
  var idn = $(this).parent().attr("id").split("_")[1];
  alert(idn); //return NodeID    
});
Run Code Online (Sandbox Code Playgroud)

如果只需要dblclicked节点,请插入此项

if (this.className.indexOf('icon') == -1) {  /* is the node clicked a leaf? */ }
Run Code Online (Sandbox Code Playgroud)