/** * Load les infos depuis une string JSON * * @access public * @param string $json La string JSON * @return TafelTree Le TafelTree créé */ public function loadJSON($json, $id, $imgs = 'imgs/', $width = '100%', $height = 'auto', $options = array()) { $tree = new TafelTree($id, $imgs, $width, $height, $options); $service = new Services_JSON(); $tree->items = TafelTree::loadServiceJSON($service->decode($json)); return $tree; }
// Manipulate the object (or array of objects) $first = $branches[0]; echo '<h3>CASE 1 : load structure from a JSON string</h3>'; echo 'First JSON branch : ' . $first->getText() . ' (' . $first->getId() . ')'; echo '<ul>'; foreach ($first->items as $next) { echo '<li>Next JSON branch : ' . $next->getText() . ' (' . $next->getId() . ')</li>'; } echo '</ul>'; /// // CASE 2 : create a loader TafelTree from an object // /// // Create the tree (same options as javascript). In this sample, the file // drop.php doesn't exist. It's just to show how to manage ajax declarations $tree = new TafelTree('divTree', '../imgs/', null, null, array('generate' => true, 'onMouseOver' => 'myMouseover', 'onMouseOut' => 'myMouseout', 'defaultImg' => 'page.gif', 'lineStyle' => 'full', 'onDropAjax' => array('funcDrop', 'drop.php'))); // Add a root branch $b1 = $tree->addBranch('r1', 'root'); // Add two branches into the root $b1->addBranch('b1', 'branch 1', array('onclick' => 'testclick', 'thing' => 1)); $b1->addBranch('b2', 'branch 2'); ?> <html> <head> <title>PHP4 sample</title> <link rel="stylesheet" href="../css/tree.css" type="text/css" /> <script src="../js/prototype.js" type="text/javascript"></script> <script src="../js/scriptaculous.js" type="text/javascript"></script> <script src="../Tree.js" type="text/javascript"></script> <script type="text/javascript"> function myMouseover (branch) {