jstree create new Node does not work

Asked

Viewed 82 times

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.

1 answer

1


I found that a simple configuration was missing, found according to this reply.

$('#tree').jstree({
    'core': {
        'check_callback': true
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.