jsTree Get new node AFTER node is created

冷暖自知 提交于 2020-02-15 13:45:54

问题


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);
                        }
                    }
                }

回答1:


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);
});


来源:https://stackoverflow.com/questions/31733744/jstree-get-new-node-after-node-is-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!