Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsTree Get new node AFTER node is created

I am attempting to obtain the text value of the newly created node AFTER the user edits the name of the new node and presses Enter.

When I do this:

        .on('create_node.jstree', function (e, data) {
            var id = data.node.id;
            alert($('#' + id).text());
        });

All I get is "New Node" in my alert. I have been scouring this site for an answer as well as perusing the API documentation on the jstree website for some time, But they provide few examples, so as a jQuery novice, it is pretty difficult for me to understand.

So, my question is which event do I actually need to program against to be able to obtain the ID of the node that was just created? is it the changed.jstree event? If so, how do I utilize this?

EDIT Might help to mention I am attempting this through a context menu; Here is how I have my "create" item set up:

                items = {
                    "create": {
                        "label": "New Category",
                        "action": function (obj) {
                            $node = tree.create_node(node);
                            tree.edit($node);
                        }
                    }
                }
like image 751
taki Martillo Avatar asked Nov 02 '25 15:11

taki Martillo


1 Answers

The event you might be looking for is rename_node.jstree. It would look like:

.on('rename_node.jstree', function (e, data) {
  //data.text is the new name:
  alert(data.text);
});
like image 180
Sam H. Avatar answered Nov 04 '25 05:11

Sam H.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!