0
Guys I’m using the jstree to create a tree.
I’m trying to create a new Ode, but I’m not getting it.
The first level of Node will already be loaded into html, so only the next ones will be added by js. Follow an example:
$("#tree").jstree();
$("#tree").on("click",function(){
var nodeSelecionado = jQuery("#tree").jstree("get_selected");
console.log(nodeSelecionado[0]);
jQuery("#tree").jstree('create_node', $("#"+nodeSelecionado[0]), "node novo", 'last');
jQuery("#tree").jstree("open_node", $("#"+nodeSelecionado[0]));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.0.8/jstree.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.0.8/themes/default/style.min.css" rel="stylesheet"/>
<div id="tree">
<ul>
<li class="jstree-closed">Node 1</li>
<li class="jstree-closed">Node 2</li>
</ul>
</div>
Thanks for the help.