gpt4 book ai didi

javascript - [jsTree] : why the 'rename' and 'move' events are not fired with new nodes?

转载 作者:搜寻专家 更新时间:2023-11-01 05:25:57 25 4
gpt4 key购买 nike

我在网页中使用 jstree 作为 TreeView 。

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

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

似乎事件只与初始节点绑定(bind)。我没有看到任何将事件与之后创建的节点绑定(bind)的“实时”方法。

有没有可能做到这一点?

这是一个有助于(我希望)理解我的问题的示例:

 $(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"});
});
});

最佳答案

我认为命令是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"
});
});
});

我知道这是主观的,但请相信它是有值(value)的。

关于javascript - [jsTree] : why the 'rename' and 'move' events are not fired with new nodes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6875187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com