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.
javascript jquery jstree
taki martillo
source share