12

I am trying to add a new node in jstree programmatically on button click, as well as on contextmenu create click, but there is some issue.

Here is the link of fiddle.

<div id="jstree">
  </div>
<button id="sam">create node</button>
Opal
  • 81,889
  • 28
  • 189
  • 210
Sunil Madan
  • 457
  • 1
  • 4
  • 17

1 Answers1

13

Here is your fiddle, fixed to work: http://jsfiddle.net/3q9Ma/223/

You were calling create_node with an array, which was wrong, also the string value 'null' was not the correct way to create a root node - use the special string value '#' (in later versions null works too, but not as a string).

You might consider upgrading the jstree version - your fiddle was using a very early beta. Also keep in mind jstree itself does not require Angular.

vakata
  • 3,726
  • 1
  • 17
  • 31
  • Thank you for this answer. This code works great if you only add one node. However, if you are adding further nodes, you create them with duplicate IDs. Therefore, only the first created node is selectable. You can generate IDs with consecutive numbers to solve this problem. – Michaela Nov 02 '18 at 09:40