How to listen for double-click on jstree?

岁酱吖の 提交于 2019-12-06 00:44:04

问题


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 href value into an input field in a form somewhere.)


回答1:


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.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.

data : Contains the metadata.




回答2:


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



来源:https://stackoverflow.com/questions/5932876/how-to-listen-for-double-click-on-jstree

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