最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to listen for double-click on jstree? - Stack Overflow

programmeradmin3浏览0评论

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

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

Share Improve this question asked May 9, 2011 at 5:26 Alex ReynoldsAlex Reynolds 96.9k59 gold badges250 silver badges351 bronze badges 1
  • Possible duplicate of How can I attach custom behaviour to a double click in jsTree? – Rob Forrest Commented Oct 23, 2015 at 12:15
Add a comment  | 

2 Answers 2

Reset to default 13

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.

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

发布评论

评论列表(0)

  1. 暂无评论