jstree:删除节点事件不起作用
jstree : delete node event not working
下面是我使用的代码。删除节点时 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");
});
如何解决这个问题?
根据 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,这可能会导致问题,具体取决于它们如何侦听事件(它们可以在创建实例时添加挂钩,此时您的版本具有 none)。
差不多了 - 您应该将 'check_callback': true
放在 core
属性 下,如下所示。检查演示 - Fiddle Demo
$('#tree-container').jstree({
'plugins' : ['contextmenu'],
'core' : {
'check_callback' : true,
...
}
});
下面是我使用的代码。删除节点时 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");
});
如何解决这个问题?
根据 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,这可能会导致问题,具体取决于它们如何侦听事件(它们可以在创建实例时添加挂钩,此时您的版本具有 none)。
差不多了 - 您应该将 'check_callback': true
放在 core
属性 下,如下所示。检查演示 - Fiddle Demo
$('#tree-container').jstree({
'plugins' : ['contextmenu'],
'core' : {
'check_callback' : true,
...
}
});