javascript 如何监听双击jstree?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5932876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 18:50:44  来源:igfitidea点击:

How to listen for double-click on jstree?

javascriptjqueryeventsjstreedouble-click

提问by Alex Reynolds

How would I write a listener for a double-click event on a jstree object? (For example, I'd like to double-click on a tree node and paste its anchor's hrefvalue into an inputfield in a form somewhere.)

我将如何为 jstree 对象上的双击事件编写侦听器?(例如,我想双击一个树节点并将其锚点的href值粘贴到某个input表单中的某个字段中。)

回答by Nirmal

I have used something like this way back a year ago, i don't know if there's any change in the current jstree version :

一年前我用过这样的东西,我不知道当前的 jstree 版本是否有任何变化:

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

node :Contains the li that is being clicked.

node :包含被点击的 li。

data :Contains the metadata.

data :包含元数据。

回答by r00pert

Nirmal's solution works if you click anywhere on the jstree div. I wanted to enable double click only on the nodes themselves and not, for example, on the whitespace to the right. changing the solution a little enabled this:

如果您单击 jstree div 上的任意位置,Nirmal 的解决方案就会起作用。我只想在节点本身上启用双击,而不是在右侧的空白处启用双击。稍微改变解决方案可以实现这一点:

$('#jstree-div a').live('dblclick',function (e) {
    var node = $(e.target).closest("li");
    var type = node.attr('rel');
    var item = node[0].id;

    // do stuff...
});

Not sure why the 'rel' and the 'id' attributes are in different places in the resulting node, but it works ;)

不知道为什么 'rel' 和 'id' 属性在结果节点中的不同位置,但它有效;)