[jsTree]:为什么'rename'和'move'事件不是用新节点触发的?

luc*_*luc 4 javascript jquery events jstree

我在网页中使用jstree作为树视图.

树可以重命名和移动节点.移动或重命名节点会触发rename_node.jstree和rename_node.jstree事件.

使用新节点(使用rename_node.jstree events)创建时,仍可以重命名和移动节点,但不会触发move_node.jstree和rename_node.jstree事件.

似乎事件只与初始节点绑定.我没有看到任何"实时"方法将事件与之后创建的节点绑定.

有没有可能这样做?

这是一个帮助(我希望)了解我的问题的示例:

 $(function(){
    $("#nodes").jstree({ 
        "plugins" : [ "themes", "html_data", "dnd", "ui", "crrm" ]
    }).bind("move_node.jstree", function (event, data) {
        alert('move');
    }).bind("rename_node.jstree", function (event, data) {
        alert('rename');
    }).bind("create_node.jstree", function (event, data) {
        alert('create_node');
    })

    $("#create_button").click(function () { 
        $("#nodes").jstree("create",null,"last",{data:"name"}); 
    });
});
Run Code Online (Sandbox Code Playgroud)

Lev*_*son 5

我认为这个命令create_node不是create.有关更多详细信息,请访问http://www.jstree.com/documentation/core.


仅供参考,您的代码可以更好地编写为:

$(function() {
    $("#nodes").jstree({
        "plugins": ["themes", "html_data", "dnd", "ui", "crrm"]
    }).bind("move_node.jstree rename_node.jstree create_node.jstree", function(event, data) {
        var type = event.type;
        alert(type);
        if (type === 'move_node.jstree') {
            //handle move_node.jstree here
        } else if (type === 'rename_node.jstree') {
            //handle rename_node.jstree here
        } else if (type === 'create_node.jstree') {
            //handle create_node.jstree here
        }

    });

    $("#create_button").click(function() {
        $("#nodes").jstree("create", null, "last", {
            data: "name"
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

我知道这是主观的,但要把它当作值得的东西.