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)