If you want your data to be dynamic, you can use the following code to initialize jstree:
$('#jstree').jstree({ 'core': { 'data': arrayCollection } });
where arrayCollection is a variable that binds your dynamic array. For example, your arrayCollection might look like this:
var arrayCollection = [ {"id": "animal", "parent": "#", "text": "Animals"}, {"id": "device", "parent": "#", "text": "Devices"}, {"id": "dog", "parent": "animal", "text": "Dogs"}, {"id": "lion", "parent": "animal", "text": "Lions"}, {"id": "mobile", "parent": "device", "text": "Mobile Phones"}, {"id": "lappy", "parent": "device", "text": "Laptops"}, {"id": "daburman", "parent": "dog", "text": "Dabur Man", "icon": "/"}, {"id": "Dalmation", "parent": "dog", "text": "Dalmatian", "icon": "/"}, {"id": "african", "parent": "lion", "text": "African Lion", "icon": "/"}, {"id": "indian", "parent": "lion", "text": "Indian Lion", "icon": "/"}, {"id": "apple", "parent": "mobile", "text": "Apple IPhone 6", "icon": "/"}, {"id": "samsung", "parent": "mobile", "text": "Samsung Note II", "icon": "/"}, {"id": "lenevo", "parent": "lappy", "text": "Lenevo", "icon": "/"}, {"id": "hp", "parent": "lappy", "text": "HP", "icon": "/"} ];
Finally, your html file should look like this:
<html> <head> <title>JSTree</title> <link rel="stylesheet" href="dist/themes/default/style.css" /> <script src="dist/libs/jquery.js"></script> <script src="dist/jstree.js"></script> <script> $(function() { var arrayCollection = [ {"id": "animal", "parent": "#", "text": "Animals"}, {"id": "device", "parent": "#", "text": "Devices"}, {"id": "dog", "parent": "animal", "text": "Dogs"}, {"id": "lion", "parent": "animal", "text": "Lions"}, {"id": "mobile", "parent": "device", "text": "Mobile Phones"}, {"id": "lappy", "parent": "device", "text": "Laptops"}, {"id": "daburman", "parent": "dog", "text": "Dabur Man", "icon": "/"}, {"id": "Dalmation", "parent": "dog", "text": "Dalmatian", "icon": "/"}, {"id": "african", "parent": "lion", "text": "African Lion", "icon": "/"}, {"id": "indian", "parent": "lion", "text": "Indian Lion", "icon": "/"}, {"id": "apple", "parent": "mobile", "text": "Apple IPhone 6", "icon": "/"}, {"id": "samsung", "parent": "mobile", "text": "Samsung Note II", "icon": "/"}, {"id": "lenevo", "parent": "lappy", "text": "Lenevo", "icon": "/"}, {"id": "hp", "parent": "lappy", "text": "HP", "icon": "/"} ]; $('#jstree').jstree({ 'core': { 'data': arrayCollection } }); }); </script> </head> <body> <div id="jstree"></div> </body> </html>
Whenever an arrayCollection changes, you must reassign the arrayCollection to jstree and programmatically update jstree.