SOURCE CODE: Tree Menu From JSON
VIEW EXAMPLE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Tree Menu From JSON | JavaScript Examples | UIZE JavaScript Framework</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="keywords" content="featured widget menu Uize.Widgets.NavTree.Menu.Widget"/>
  <meta name="description" content="See a demo of JavaScript menus, that can be easily built from a JSON object and can even be dynamically updated. These menus also support separators."/>
  <link rel="alternate" type="application/rss+xml" title="UIZE JavaScript Framework - Latest News" href="http://www.uize.com/latest-news.rss"/>
  <link rel="stylesheet" href="../css/page.css"/>
  <link rel="stylesheet" href="../css/page.example.css"/>
</head>

<body>

<script type="text/javascript" src="../js/Uize.js"></script>

<h1 class="header">
  <a id="page-homeLink" href="../index.html" title="UIZE JavaScript Framework home"></a>
  <a href="../index.html" class="homeLinkText" title="UIZE JavaScript Framework home">UIZE JavaScript Framework</a>
</h1>

<div class="main">
  <h1 class="document-title">
    <a href="../javascript-examples.html" class="breadcrumb breadcrumbWithArrow">JAVASCRIPT EXAMPLES</a>
    Tree Menu From JSON
    <div class="pageActionsShell">
      <div id="page-actions" class="pageActions"><a href="source-code/tree-menu.html" class="buttonLink">SOURCE</a></div>
    </div>
  </h1>

  <!-- explanation copy -->

  <div class="explanation">
    <p>In this example, an instance of <a href="../reference/Uize.Widgets.NavTree.Menu.Widget.html"><code>Uize.Widgets.NavTree.Menu.Widget</code></a> is instantiated to produce a multi-level menu. The markup for the menu is generated when the widget is wired up. The structure for the markup is driven by a JSON data structure that is supplied to the <code>items</code> state property of the widget. This data structure is purely for demonstration purposes, so none of the items have active links specified (i.e. clicking does nothing). The generated markup does not contain any styling, and the decoration for the menu is controlled by separate CSS in the page. As you interact with the menu, notice how the selection path is highlighted as you go deeper into submenus. Lower down the page, below the menu, are some links that execute snippets of code to demonstrate the programmatic interface of the widget.</p>
  </div>

  <div id="page-treeMenu" style="height:200px;"></div>

  <!-- programmatic interface examples -->

  <div class="programmaticInterface">
    <ul>
      <li>
        <a href="javascript://" class="linkedJs">treeMenu.set ({items:animalsAndPlants})</a><br/>
        <ul>
          <li><a href="javascript://" class="linkedJs">treeMenu.collapseAllBut (['Animals','Wild Animals','Cats','Tiger'])</a></li>
          <li><a href="javascript://" class="linkedJs">treeMenu.collapseAllBut (['Plants','Bushes and Shrubs','Hedges','Escallonia'])</a></li>
        </ul>
      </li>
      <li>
        <a href="javascript://" class="linkedJs">treeMenu.set ({items:Uize.Test.TestData.Animals ()})</a><br/>
        <ul>
          <li><a href="javascript://" class="linkedJs">treeMenu.collapseAllBut (['Pets','Dogs','Large Breeds'])</a></li>
        </ul>
      </li>
      <li>
        <a href="javascript://" class="linkedJs">treeMenu.set ({items:Uize.Test.TestData.Plants ()})</a><br/>
        <ul>
          <li><a href="javascript://" class="linkedJs">treeMenu.collapseAllBut (['Trees','Deciduous'])</a></li>
        </ul>
      </li>
      <li><a href="javascript://" class="linkedJs">treeMenu.setExpandedDepth (0)</a></li>
    </ul>
  </div>
</div>

<!-- JavaScript code to create tree menu instance and insert and wire its UI -->

<script type="text/javascript">

Uize.require (
  [
    'UizeSite.Page.Example.library',
    'UizeSite.Page.Example',
    'Uize.Widgets.NavTree.Menu.Widget',
    'Uize.Test.TestData.Animals',
    'Uize.Test.TestData.Plants',
    'Uize.Test.TestData.AnimalsAndPlants'
  ],
  function () {
    'use strict';

    /*** create the example page widget ***/
      var page = window.page = UizeSite.Page.Example ({evaluator:function (code) {eval (code)}});

    /*** add the tree menu child widget ***/
      var
        animalsAndPlants = Uize.Test.TestData.AnimalsAndPlants (),
        treeMenu = page.addChild (
          'treeMenu',
          Uize.Widgets.NavTree.Menu.Widget,
          {
            items:animalsAndPlants,
            built:false
          }
        )
      ;

    /*** wire up the page widget ***/
      page.wireUi ();
  }
);

</script>

</body>
</html>