[jsTree]: why don't the rename and move events fire with new nodes?

I am using jstree for tree view on web page.

The tree allows you to rename and move nodes. Moving or renaming a node raises the rename_node.jstree and rename_node.jstree events.

With new nodes (created using rename_node.jstree events ), the node can be renamed and moved, but the move_node.jstree and rename_node.jstree events do not fire.

It seems that events are only related to internal nodes. I do not see any "live" method for binding events to nodes created after.

Is there any way to do this?

Here is an example 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"}); }); }); 
+4
source share
2 answers

It seems that the events are fired correctly. The problem was somewhere in the logic. I also needed to set the item id correctly.

 $("#nodes").jstree("create",null,"last",{data:the_name, attr: {id: the_id}}); 

Sorry for this mistake.

+2
source

The create_node command, not create , I think. See http://www.jstree.com/documentation/core for more details.


FYI, your code will be better written as:

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

I know that this is subjective, but take it for what it costs.

+5
source

All Articles