Jstree : dblclick binding parameter data is undefined

最后都变了- 提交于 2019-12-04 03:43:39

问题


I try to use good lib jstree but i have some strange problem with dblclick binding. Here is my code

$("#basic_html").jstree({
    themes: {
        url: "http://mywork/shinframework/shinfw/themes/redmond/css/jstree/default/style.css"
    },
    "plugins" : ["themes","html_data","ui","crrm","hotkeys", "core"],
});

$("#basic_html").bind("dblclick.jstree", function (e, data) {
    alert(e);
    alert(data);
});

When this code runs and i make dblclick for some node i can see 2 alerts. The first is object -right, the second is undefined - BUT i want receive data information.

Please, if some specialist solve this problem give me right way for correct use dblclick and receive "data" information about node who is i clicked.

Thanks


回答1:


I recommend this approach . . .

$("#basic_html li").live("dblclick", function (data) {
   //this object is jsTree node that was double clicked
   ...
});

First, you usually only need to know if the li was clicked so monitoring the event on the li will give you everything you need. Secondly, use live or delegate for the event binding so you can manipulate the tree without breaking the event.

Once you have the node that was double clicked (the this object) you can then use the built-in functions like this . . .

if (!jsAll.is_selected(this)) { return false; } //cancel operation if dbl-clicked node not selected

Where . . .

jsAll = $.jstree._reference("basic_html")



回答2:


$("#basic_html").bind("dblclick.jstree", function (event) {
    var node = $(event.target).closest("li");//that was the node you double click
});

that's the code you want.



来源:https://stackoverflow.com/questions/6043987/jstree-dblclick-binding-parameter-data-is-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!