Before posting this question, I checked other questions on stackoverflow. one of them:
creating a new node in jstree
But for some reason I canβt get it to work.
I get node information for children through ajax. When you click on node, it will call an ajax request and get the node's child information. I want to bind this data to the parent (by clicking) node in jstree.
Here is the jsfiddle daemon (without ajax): https://jsfiddle.net/8wyqd9om/
Could you help me with 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);
});
});
source
share