jstree:删除节点事件不起作用

时间:2017-05-10 15:39:11

标签: javascript jquery jstree

以下是我使用的代码。删除节点时,不会触发delete_node.jstree。

     $('#tree-container').jstree({
    'plugins' : ['contextmenu'],
    "check_callback" : true,
    'core' : {
        'data' : {
            "url" : sTreeUrl + "?operation=gettree",
            "dataType" : "json" ,
            'data' : function (node) {
                  return { 'parent' : node.id, 'tenantid' : tenantid };
                }
        }
    }
    });
    $('#tree-container').on("delete_node.jstree", function (e, data) {
        alert("s");
    });

如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

几乎就是 - 您应该将'check_callback': true置于core属性下,如下所示。查看演示 - Fiddle Demo

$('#tree-container').jstree({
    'plugins' : ['contextmenu'],    
    'core' : {
        'check_callback' : true,
        ...
    }
});

答案 1 :(得分:0)

根据their example,您可以在jstree()实例化之前链接事件委托,如下所示:

$('#tree-container').on("delete_node.jstree", function (e, data) { // listen for the event
  alert("s");
}).jstree({ //create the instance
    'plugins' : ['contextmenu'],
    "check_callback" : true,
    'core' : {
        'data' : {
            "url" : sTreeUrl + "?operation=gettree",
            "dataType" : "json" ,
            'data' : function (node) {
                  return { 'parent' : node.id, 'tenantid' : tenantid };
                }
        }
    }
});

我没有对此进行测试,也没有自己使用它,但它可能有所帮助。您的示例是在注册事件之前实例化jstree,这可能会导致问题,具体取决于他们如何监听事件(他们可以在创建实例时添加挂钩,此时您的版本没有)。