Double-click event code for adding a node in jquery. jstree _ jquery

Source: Internet
Author: User
This article adds a node double-click event based on jsTree1.0-rc1. 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 is

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

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

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

The 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_node

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