[jsTree]:为什么要“重命名”?并“移动”新节点不会触发事件?
我在网页中使用 jstree 作为树视图。
该树使得重命名和移动节点成为可能。移动或重命名节点会触发 rename_node.jstree 和 rename_node.jstree 事件。
对于新节点(使用 rename_node.jstree 事件
创建),仍然可以重命名和移动节点,但不会触发 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"});
});
});
I am using jstree for a tree view in a web page.
The tree makes possible to rename and move nodes. Moving or renaming a node fires the rename_node.jstree and rename_node.jstree events.
With new nodes (created with rename_node.jstree events
), the node can still be renamed and moved but the move_node.jstree and rename_node.jstree events are not fired.
It seems that the events are only bound with the inital nodes. I don't see any 'live' method to bind the events with nodes created after.
Is there any possibility to do that?
Here is a sample that helps (I hope) to understand my problem:
$(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"});
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为该命令是
create_node
,而不是create
。有关更多详细信息,请参阅 http://www.jstree.com/documentation/core。仅供参考,您的代码最好写为:
我知道这是主观的,但请考虑它的价值。
The command is
create_node
, notcreate
, I think. See http://www.jstree.com/documentation/core for more details.FYI, your code would be better written as:
I know that is subjective, but take it for what is worth.
看来事件已正确触发。问题出在逻辑上的某个地方。我也必须设置该项目的 id 才能正确处理。
为这个错误感到抱歉。
It seems that the events are fired correctly. The problem was somewhere in the logic. I had to set the id of the item too to be handled correctly.
Sorry for this mistake.