JsTree - unable to create a new node - all other functions work well

Deselect and bring funcntions to fina, but create / delete / rename none.

What to do wrong?

info.json contains 5 nodes, labeled 1 to 5.

<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="jstree\dist\themes\default\style.min.css" />
<script src="jstree\dist\jstree.js"></script>
<script>
$(function() {

$('#test_tree').jstree({
'core' : {
  'data' : {
    'url' : 'info.json',
    'data' : function (node) {
      return { 'id' : node.id };
    }
  }
  }
});
}); 
</script>

</head>
<body>

<div id="container" >

  <div id="nav_bar">
    <button id="create" onclick = "demo_create()">Create</button>
  </div> 
  <div id="test_tree"></div
</div>  

<script>
            function demo_create() {
$.jstree.reference('#test_tree').hover_node('ajson5');
$.jstree.reference('#test_tree').deselect_node('ajson1');
$.jstree.reference('#test_tree').create_node();
            };

</script>

</body>

I used the same example from the official site, but it doesn’t work. Thanks for any help.

+3
source share
6 answers

First, in order for the changes to be made to the tree, the checkcallback in the kernel configuration must be set to true.

$('#test_tree').jstree({
    'core' : {
        'data' : {
        'url' : 'info.json',
        'data' : function (node) {
            return { 'id' : node.id };
        },
        check_callback : true
    }
}

You need to at least pass parent.id to the create_node function.

$.jstree.reference('#test_tree').create_node('ajson1');

You can check the API on jstree for a complete list of parameters.

+10
source

You should set the type of the newly created node as follows:

$('#tree').jstree().create_node('#', {'id': 'blah', 'text': 'new node', 'type': 'folder'}, 'last', function() {
    console.log('done');
});

jstree .

+2

. ( http://www.jstree.com/demo/):

var tree = $("#test_tree").jstree(true);
var sel = tree.get_selected();
if (!sel.length) 
{
    return false;
}
sel = sel[0];
sel = tree.create_node(sel);
if (sel) 
{
  tree.edit(sel);
}
+1

- jsTreeView 3.2.1

 $("#treeView").jstree({ 'core': {
                'check_callback': true,
                'themes': {
                    "variant": "large"
                },
                'data':
               [{"id":"1","parent":"#","text":"Parent Node"}]
                }
            });

check_callback, . 'check_callback': true.

Node

var ref_treeview = $("#treeView").jstree(true);
sel = ref_treeview.get_selected();
if (!sel.length) {
    return false;
}
sel = sel[0];
sel = ref_treeview.create_node(sel, "childNode", "last", CreateNode,true);

CreateNode -

+1

, :
, . API ajax.

function makeNode(menunode, menuname){
    var inst = $.jstree.reference("#treemenu"); //get menu instance
    var obj = inst.get_node(menunode);
    inst.create_node(obj, menuname); //creates nodes. use "#" to make root nodes
    inst.open_node(obj); // open the node (unfold)
});

:

//create menu instance and allow tree changes
$('#treemenu').jstree({'core' : {'check_callback': true}});

makeNode("#", "main menu"); //makes root node
makeNode("#j1_1", "submenu in main menu"); //makes sub node

, div id="treemenu"

<div id="treemenu"></div>
0

, jstree, 'core', :

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

All Articles