javascript - jstree: create a new child node -
before posting i've checked other questions on stackoverflow. 1 this:
but somehow i'm not able working.
i'm fetching child node details through ajax. when click on node trigger ajax request , child node details. want attach these details parent(clicked) node in jstree.
here jsfiddle demo(without ajax): https://jsfiddle.net/8wyqd9om/
can please me this?
html:
<div id='cat_tree'> <ul> <li id="1">first <ul> <li id="2">first</li> <li id="3">first</li> </ul> </li> <li id="4">first</li> <li id="5">first</li> <li id="6">first</li> </ul> </div>
js:
$(function () { $('#cat_tree').jstree({"core": { "themes":{ "icons":false } }}); var data = [ { "id" : "7", "parent" : "#4", "text" : "second" }, { "id" : "8", "parent" : "#4", "text" : "second" }, ]; $('#click').click(function() { $('#cat_tree').jstree().create_node($('#4'), data, 'last', function(){ alert("done"); }, true); }); });
please check below code
$(function() { var data = [{ "id": "p1", "parent": "#", "text": "parent-1" }, { "id": "p2", "parent": "#", "text": "parent-2" }, { "id": "c1", "parent": "p2", "text": "child 1" }, { "id": "c2", "parent": "p2", "text": "child 2" }, ]; $("#jstree").jstree({ "core": { "check_callback": true, "data": data } }).on('create_node.jstree', function(e, data) { console.log('saved'); }); $('#btncreate').click(function() { $('#jstree').jstree().create_node('#', { "id": "p3", "text": "parent-3" }, "last", function() { alert("parent created"); }); $('#jstree').jstree().create_node('p2', { "id": "c3", "text": "child 3" }, "last", function() { alert("child created"); }); }); });
Comments
Post a Comment