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

时间:2010-09-09 07:37:13

标签: jquery mouseevent double-click jstree

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

我似乎无法让它发挥作用。我在ondblclk事件中找到了一些文档,但它没有触发。

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

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

6 个答案:

答案 0 :(得分:24)

事实证明我可以这样做:

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

node包含点击的lidata包含包含我的信息的元数据。

答案 1 :(得分:6)

'dblclick.jstree'在最新版本的jsTree 1.0中不存在。

DoubleClick for node:

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

如果只需要dblclicked节点

,请插入此项
if (this.className.indexOf('icon') == -1) {  /* is the node clicked a leaf? */ }

答案 2 :(得分:4)

将数据输出给我有点不同,但GiddyUpHorsey的回答是现实的。这是代码:

        jstree.bind("dblclick.jstree", function (e, data) {
            var node = $(e.target).closest("li");
            var id = node[0].id; //id of the selected node
        });

答案 3 :(得分:2)

上述答案不适用于最新版本的jstree(即3.3.4)
这花费了我一天的心灵弯曲工作,但我终于明白了。 这是双击编辑代码:

$('#tree1').bind("dblclick.jstree", function (event) {
  var tree = $(this).jstree();
  var node = tree.get_node(event.target);
  tree.edit(node);
});

这是一个有效的jsfiddle

答案 4 :(得分:0)

作为版本3.3.5,我使用了这个:

<b-img :src="require('../static/picture.jpg')" />

<b-card-img :img-src="require('../static/picture.jpg')" />

答案 5 :(得分:0)

对我有用

$("#MyTree").on('dblclick','.jstree-anchor', function (e) {
    var instance = $.jstree.reference(this),
    node = instance.get_node(this);
    console.log(node);
});