I am trying to dynamically load the nodes of a jtree when they are expanded. The little documentation I found is at the end of this page.
I found some solutions that cre
Extending Nathans answer with a (very minimalistic) example: the Demo tree with lazy loading.
JS:
$('#the_tree').jstree({
'core' : {
'data' : {
'url' : "tree/ajax.php",
'data' : function (node) {
return { 'id' : node.id };
}
}
},
});
PHP:
header('Content-Type: application/json');
if ( $_GET["id"] === "#" ) {
$data = array(
array( "id" => "ajson1", "parent" => "#", "text" => "Simple root node" ),
array( "id" => "ajson2", "parent" => "#", "text" => "Root node 2", "children" => true ),
);
}
else if ( $_GET["id"] === "ajson2" ) {
$data = array(
array( "id" => "ajson3", "parent" => "ajson2", "text" => "Child 1" ),
array( "id" => "ajson4", "parent" => "ajson2", "text" => "Child 2" )
);
}
echo json_encode( $data);
only Nodes that have "children" : true
, will generate a request for children when opened, other nodes are treated as leaves.