Jquery.jstree Add a node to the double-click event code _jquery

Source: Internet
Author: User
Jstree is a tree plug-in based on jquery, support drag-and-drop, copy, delete, shortcut, multiple selection, custom node icon, custom right-click menu, cross page save state, etc., anyway, I think of it basically have, and the most commendable is that it makes people feel not slow oh.

Jstree has node selection events, i.e.
 code as follows:

. Bind ("Select_node.jstree", function (E, data) {
Alert (data.rslt.obj.attr ("id") + ":" + data.rslt.obj.attr ("rel"));
})


Actually I think it's more like a node Click event, because it triggers every time the node is clicked, regardless of whether the node was previously selected.

Recently do a file management Dongdong, need to use the node of the double-click event, such as double-click a node to open the node's edit page.

Jstree Although there is a double-click event, but not for the node, but you double-click the area of the tree will trigger, as shown in any one place.

The closest thing to a node-double-clicked event is the node-selection event, which is "divert".

Analysis
After line No. 833 This.get_container () is the node's Click event
 code as follows:

. Delegate ("A", "Click.jstree", $.proxy (function (event) {
Event.preventdefault ();
This.select_node (Event.currenttarget, True, event);
}, this))


Again I'm here insert node double-click event
 code as follows:

. Delegate ("A", "Dblclick.jstree", $.proxy (function (event) {
Event.preventdefault ();
This.dblclick_node (Event.currenttarget, True, event);
}, this))


Then, I can realize the Dblclick_node method.

It is more complicated to find Select_node code on line No. 928. But inside 90% is no use for double clicks, such as processing radio, multiple selection, saving selection results to cookies and so on. Therefore, the implementation of Dblclick_node method is much simpler than select_node.
 code as follows:

Dblclick_node:function (obj, check, e) {
obj = This._get_node (obj);
if (obj = = 1 | |!obj | |!obj.length) {return false;}
This.__callback ({"obj": obj});
},


OK, that's it.

Use examples
Same as Select_node usage.
 code as follows:

. Bind ("Dblclick_node.jstree", function (E, data) {
Alert (data.rslt.obj.attr ("id") + ":" + data.rslt.obj.attr ("rel"));
})


Modified code Download/201007/yuanma/jquery.jstree.rar
Oh, by the way.
Jstree with another plug-in jquery validate is incompatible, when both coexist, jstree although can also build trees out, but such as zombies generally can not unfold. Mark one here and try to revise it later.

Author: Bruce (art world of programming)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.