1

I use the code below to successfully create a new tree node in jstree outside of contextmenu. My question is how can you dynamically RENAME the text in a tree node in a similar manner outside of the contextmenu? Is there a .jstree("rename" ....) function that can be called to accomplish this? Much appreciated!

$("#RequirementsTree").jstree("create", null, "last", {"data" : "new_node_text",
                  "state" : "open",
                  "attr" :  { "id" : "new_node_id", "name" : "requirement" }, 
 });

I've tried the following:

        .bind("select_node.jstree", function(event, data) {
            ReqNode = data.rslt;

 $("#RequirementsTree").rename_node(ReqNode, "test");

That didn't work, however. Is there something I'm doing wrong?

TheDude
  • 1,421
  • 4
  • 29
  • 54
  • Probably better off sourcing the jstree site for a list of it's documentation, it will outline straight away if it's capable.http://www.jstree.com/documentation – Shannon Sep 15 '12 at 03:02
  • I looked there and tried $("#RequirementsTree").rename_node(ReqNode, "test"); That didn't work, however. – TheDude Sep 15 '12 at 03:14

5 Answers5

2

This should work for you:

$("#demo1").jstree('set_text', [node , text] );
$("#demo1").jstree('rename_node', [node , text] );

JSTree Core Documentation...

how-can-i-rename-a-jstree-node

Community
  • 1
  • 1
Mortalus
  • 10,574
  • 11
  • 67
  • 117
  • I don't know what the deal is. I tried both of those options you suggested and neither worked. I know that I'm getting the li element since I can change the class on it, but that "rename_node" and "set_text" are just not working for some reason. Should I be using something other than the li element for that particular node? – TheDude Sep 15 '12 at 12:16
  • 1
    @TheDude "node" needs to be at the
  • level ID. Try to log $(node).attr("id") to see what value shows. Remember to pass over the # with the ID string. $("#demo1").jstree('set_text', ["#myID" , "SomeText"] );
  • – MMeah Sep 22 '12 at 23:24
  • I have to change the syntax to `$("#demo1").jstree('rename_node', [node ], text );` then it worked. – Twix Jan 02 '16 at 06:20