如何在jsTree中双击自定义行为?
我正在使用jsTree jQuery插件,并希望在用户双击节点时执行代码。
我似乎无法让它发挥作用。 我在ondblclk
事件上找到了一些文档,但它没有触发。
browser.jstree( { plugins: ["themes", "json_data", "ui", "cookies"], callback: { ondblclk: function (node, tree) { if (!thisReportBrowserthis._isFoldersOnly) { var f = node; } } } } );
如何使用jstree处理双击事件?
事实certificate我可以做到这一点:
jstree.bind("dblclick.jstree", function (event) { var node = $(event.target).closest("li"); var data = node.data("jstree"); // Do my action });
node
包含单击的li
, data
包含包含my信息的元数据。
最后一个版本jsTree 1.0中不存在’dblclick.jstree’。
DoubleClick for node:
$("#yourtree").delegate("a","dblclick", function(e) { var idn = $(this).parent().attr("id").split("_")[1]; alert(idn); //return NodeID });
如果只需要dblclicked节点,请插入此项
if (this.className.indexOf('icon') == -1) { /* is the node clicked a leaf? */ }
获取数据对我来说有点不同,但GiddyUpHorsey的回答是现实的。 这是代码:
jstree.bind("dblclick.jstree", function (e, data) { var node = $(e.target).closest("li"); var id = node[0].id; //id of the selected node });
以上答案不适用于最新版本的jstree(3.3.4)
这花了我一天的心灵弯曲工作,但我终于明白了。 这是双击编辑代码:
$('#tree1').bind("dblclick.jstree", function (event) { var tree = $(this).jstree(); var node = tree.get_node(event.target); tree.edit(node); });
作为版本3.3.5,我正在使用这个:
$('#jstree').on("dblclick.jstree", function (e) { var instance = $.jstree.reference(this), node = instance.get_node(e.target); // Code });