<?php /* Created by Marco Gaido on 25/08/2014. */ require "../mgJQTreePHPLib.php"; $root = new mg_Node("Parent", "root"); $c1 = new mg_Node("Child", "c1"); $gc = new mg_Node("Grand Child"); $secCh = new mg_Node("Second Child"); $tert = new mg_Node("Tertiary Child"); $with3Sons = new mg_Node("Child with 3 Sons"); $leaf = new mg_Node("Leaf", "", true); $son = new mg_Node("Son"); $son2 = new mg_Node("Son2"); $son->setProperty("test", 12); $tree = new mg_Tree($root); $tree->addNewChild($root, $c1); $tree->addNewChild($root, $secCh); $tree->addNewChild($c1, $gc); $tree->addNewChild($secCh, $tert); $tree->addNewChild($secCh, $with3Sons); $tree->addNewChild($with3Sons, $leaf); $tree->addNewChild($with3Sons, $son); $tree->addNewChild($with3Sons, $son2); ?> <!DOCTYPE html> <html> <head> <title>Tree</title>
private static function recursTreeLoading(&$tree, &$node, $jsonNode) { foreach ($jsonNode->children as $child) { $childNode = new mg_Node($child->label, $child->id, $child->type == "leaf"); foreach ($child->infos as $name => $value) { $childNode->setProperty($name, $value); } foreach ($child->classes as $class) { $childNode->addClass($class); } $tree->addNewChild($node, $childNode); self::recursTreeLoading($tree, $childNode, $child); } }