最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jsTree Get new node AFTER node is created - Stack Overflow

programmeradmin0浏览0评论

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

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);
                        }
                    }
                }
Share Improve this question asked Jul 30, 2015 at 20:48 taki Martillotaki Martillo 4063 gold badges9 silver badges23 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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);
});
  tree.on('rename_node.jstree', function (e, data) {
  //data.text is the new name:

  var nodeId = data.node.original.id;
  if (nodeId == undefined) {
      console.log('New Node Added', data);
  } else if (data.old !== data.text) {
      console.log('Node Renamed', data);
  }});
发布评论

评论列表(0)

  1. 暂无评论