23

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

我似乎无法让它工作。我找到了一些关于某个ondblclk事件的文档,但它没有触发。

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

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

4

6 回答 6

25

事实证明我可以这样做:

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

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

于 2010-09-09T23:59:17.680 回答
6

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

节点的 DoubleClick:

$("#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? */ }
于 2010-09-19T15:49:46.683 回答
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
        });
于 2011-04-13T16:49:11.533 回答
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

于 2017-11-15T22:22:51.430 回答
1

作为 3.3.5 版,我使用的是这个:

        $('#jstree').on("dblclick.jstree", function (e) {
            var instance = $.jstree.reference(this),
            node = instance.get_node(e.target);
            // Code
        });
于 2018-02-18T20:45:08.603 回答
0

它对我有用

$("#MyTree").on('dblclick','.jstree-anchor', function (e) {
    var instance = $.jstree.reference(this),
    node = instance.get_node(this);
    console.log(node);
});
于 2020-04-22T10:12:45.137 回答