Jstree delete_node () does not delete

I combined a function to create a custom context menu for different nodes. Well, so far it is so good that the number of clicks on folders or files is displayed on different labels, but not so much on their removal.

Take a look. I had to ... make a bit of a hacky workaround because I could not get yada yada node.hasClass ('jstree-open') yada to work correctly, but this usually works on a bit, which is supposed to be removed

function customMenu(node) { //Show a different label for renaming files and folders var ID = $(node).attr('id'); if (ID == "j1_1") { return items = {}; //no context menu for the root } var $mynode = $('#' + ID); var renameLabel; var deleteLabel; var folder = false; if ($mynode.hasClass("jstree-closed") || $mynode.hasClass("jstree-open")) { //If node is a folder renameLabel = "Rename Folder"; deleteLabel = "Delete Folder"; folder = true; } else { renameLabel = "Rename File"; deleteLabel = "Delete File"; } var items = { "rename" : { "label" : renameLabel, "action": function (obj) { //nothing here yet. } }, "delete" : { "label" : deleteLabel, "action": function (obj) { //tree.delete_node($(node)); //this.remove(obj); //$('#treeView').jstree('remove', $(node)); //nothing is working. } } }; return items; } 

I have compiled a fiddle for your convenience: http://jsfiddle.net/dpzy8xjb/ I don’t think it really needs to be said that I am not super experienced with jQuery or working with third-party APIs, so ... Be careful.

+7
javascript jquery jstree
source share
2 answers

I swear to God, nothing helps me to figure out a problem faster than posting it on StackOverflow.

Fixed:

  "delete": { "label": deleteLabel, "action": function (obj) { //tree.delete_node($(node)); tree.delete_node($mynode); //<<--works. } 
+1
source share

Use tree.delete_node([node]); for removing.

Updated script

Edit:

The code you made is the same as node .

  var ID = $(node).attr('id'); var $mynode = $('#' + ID); 

Its a node object.

+2
source share

All Articles