Alex Rivera | Logout

jsTree "create_node" really not working

Asked 2012-07-04T11:53:00.047
9

I am trying to dynamically add a new node in my jsTree container. It is not working at all. I don't know what i am missing.

jsfiddle example

$("#tree").jstree({
    core: {
        "animation": 0
    },
    "html_data": {},
    "themes": {
        "icons": false
    },
    "search": {
        "case_insensitive": true,
        "show_only_matches": true
    },
    "plugins": ["themes", "html_data", "search"]
});

$("#tree").jstree("create_node", $("node_1"), "after", { "data": "Hello World" });

html:

<div id="tree">
    <ul>
        <li id="node1"><a>Hello</a></li>
    </ul>
</div>
Edit
Report

1 Answer

1

Demo simple what you need http://jsfiddle.net/gwxTa/2/ or http://jsfiddle.net/gwxTa/ or Dynamic - (click add button) http://jsfiddle.net/VBSJ8/ or http://jsfiddle.net/ak4Ed/

Please see my old post: jsTree not working

code from dynamic add button functionality:

$(function() {
    $("#tree").jstree({
        "json_data": {
            "data": [
                {
                "data": "Hello",
                "attr": {
                    "id": "root.id"
                },
                "children": [{
                    "data": "Hello World",
                    "attr": {
                        "id": "node_1"
                    },
                    "children": []}
                  ]},
                ]
        },
        "plugins": ["themes", "json_data", "crrm"]
    });
});


    $("#tree").jstree("create", $("#node_1"), "inside", {
        "data": "child2"
    }, function() {
        alert("added");
    }, true);

Hope you are including the scripts:

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>

  <link rel="stylesheet" type="text/css" href="/css/normalize.css">
  <link rel="stylesheet" type="text/css" href="/css/result-light.css">

  <script type='text/javascript' src="http://static.jstree.com/v.1.0pre/jquery.jstree.js"></script>

 <script type='text/javascript' src="http://static.jstree.com/v.1.0pre/jquery.hotkeys.js"></script>

                        
                        
answered 2012-07-04T11:59:09.500

Your Answer