Double-click event code for adding nodes in jquery. jstree

Source: Internet
Author: User

Jstree is a jquery-based tree plug-in that supports drag-and-drop, copy, delete, shortcut keys, multiple selections, custom node icons, custom right-click menus, and cross-page save statuses, in short, I think it is basically there, and the most commendable thing is that it makes people feel not slow at all.

Jstree has a node selection event, that isCopyCodeThe Code is as follows:. BIND ("select_node.jstree", function (E, data ){
// Alert (data. rslt. obj. ATTR ("ID") + ":" + data. rslt. obj. ATTR ("rel "));
})

In fact, I think it is more like a node click event, because it is triggered every time a node is clicked, regardless of whether the node has been selected.

Recently, a file management task needs to use the double-click event of a node. For example, double-click a node to open the editing page of the node.

Although there is a double-click event in jstree, It is not targeted at nodes, but is triggered in the area where you double-click the tree, such as any place.

The node selection event is the closest to the node double-click event.

Analysis
This. get_container () is the Click Event of the node.Copy codeThe Code is as follows:. Delegate ("A", "click. jstree", $. Proxy (function (event ){
Event. preventdefault ();
This. select_node (event. currenttarget, true, event );
}, This ))

Similarly, I will insert a node double-click event here.Copy codeThe Code is as follows:. Delegate ("A", "dblclick. jstree", $. Proxy (function (event ){
Event. preventdefault ();
This. dblclick_node (event. currenttarget, true, event );
}, This ))

Then, I can implement the dblclick_node method.

Finding the select_node code in Row 3 is complicated. However, "90%" is useless for double-clicking, such as processing multiple choice, multiple choice, and saving the selection result to cookies. Therefore, the implementation of the dblclick_node method is much simpler than that of select_node.Copy codeThe Code is 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.

Example
Same as select_nodeCopy codeThe Code is as follows:. BIND ("dblclick_node.jstree", function (E, data ){
// Alert (data. rslt. obj. ATTR ("ID") + ":" + data. rslt. obj. ATTR ("rel "));
})

Download the transformed code/201007/Yuanma/jquery.jstree.rar
By the way
Jstree and jquery validate, another plug-in, are difficult to deal with. When they coexist, jstree can also construct trees, but they cannot be expanded like botnets. Mark one here and try to modify it later.

By Bruce)

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.