1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
5 <title>Dijit Tree Test</title>
7 <style type="text/css">
8 @import "../../dojo/resources/dojo.css";
9 @import "css/dijitTests.css";
12 <script type="text/javascript" src="../../dojo/dojo.js"
13 djConfig="parseOnLoad: true, isDebug: true"></script>
14 <script type="text/javascript" src="_testCommon.js"></script>
16 <script language="JavaScript" type="text/javascript">
17 dojo.require("dojo.data.ItemFileReadStore");
18 dojo.require("dijit.Tree");
19 dojo.require("dijit.ColorPalette");
20 dojo.require("dijit.Menu");
21 dojo.require("dojo.parser"); // scan page for widgets and instantiate them
27 <h1 class="testTitle">Dijit Tree Test</h1>
29 <div dojoType="dojo.data.ItemFileReadStore" jsId="continentStore"
30 url="_data/countries.json"></div>
31 <div dojoType="dijit.tree.ForestStoreModel" jsId="continentModel"
32 store="continentStore" query="{type:'continent'}"
33 rootId="continentRoot" rootLabel="Continents" childrenAttrs="children"></div>
35 <h3>Tree with hardcoded root node (not corresponding to any item in the store)</h3>
36 <p>Clicking a folder node will open/close it (openOnclick==true), and clicking a leaf node will popup an alert.</p>
37 <div dojoType="dijit.Tree" id="mytree"
38 model="continentModel" openOnClick="true">
39 <script type="dojo/method" event="onClick" args="item">
40 alert("Execute of node " + continentStore.getLabel(item)
41 +", population=" + continentStore.getValue(item, "population"));
45 <button onclick="dijit.byId('mytree').destroyRecursive();">destroy</button>
47 <h2>A rootless tree (no "continents" node) with context menus, and custom icons</h2>
49 <ul dojoType="dijit.Menu" id="tree_menu" style="display: none;">
50 <li dojoType="dijit.MenuItem" onClick="alert('Hello world');">Enabled Item</li>
51 <li dojoType="dijit.MenuItem" disabled="true">Disabled Item</li>
52 <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCut"
53 onClick="alert('not actually cutting anything, just a test!')">Cut</li>
54 <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCopy"
55 onClick="alert('not actually copying anything, just a test!')">Copy</li>
56 <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconPaste"
57 onClick="alert('not actually pasting anything, just a test!')">Paste</li>
58 <li dojoType="dijit.PopupMenuItem">
59 <span>Enabled Submenu</span>
60 <ul dojoType="dijit.Menu" id="submenu2">
61 <li dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')">Submenu Item One</li>
62 <li dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')">Submenu Item Two</li>
63 <li dojoType="dijit.PopupMenuItem">
64 <span>Deeper Submenu</span>
65 <ul dojoType="dijit.Menu" id="submenu4">
66 <li dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 1!')">Sub-sub-menu Item One</li>
67 <li dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 2!')">Sub-sub-menu Item Two</li>
72 <li dojoType="dijit.PopupMenuItem" disabled="true">
73 <span>Disabled Submenu</span>
74 <ul dojoType="dijit.Menu" id="submenu3" style="display: none;">
75 <li dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')">Submenu Item One</li>
76 <li dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')">Submenu Item Two</li>
81 <div dojoType="dijit.Tree" id="tree2"
82 model="continentModel" showRoot="false" openOnClick="true">
84 <script type="dojo/connect">
85 var menu = dijit.byId("tree_menu");
86 // when we right-click anywhere on the tree, make sure we open the menu
87 menu.bindDomNode(this.domNode);
89 dojo.connect(menu, "_openMyself", this, function(e){
90 // get a hold of, and log out, the tree node that was the source of this open event
91 var tn = dijit.getEnclosingWidget(e.target);
94 // now inspect the data store item that backs the tree node:
95 console.debug(tn.item);
97 // contrived condition: if this tree node doesn't have any children, disable all of the menu items
98 menu.getChildren().forEach(function(i){ i.setDisabled(!tn.item.children); });
100 // IMPLEMENT CUSTOM MENU BEHAVIOR HERE
103 <script type="dojo/method" event="getIconClass" args="item, opened">
104 return (item == this.model.root || continentStore.getValue(item, "type") == "continent") ?
105 (opened ? "customFolderOpenedIcon" : "customFolderClosedIcon") :
108 <script type="dojo/method" event="onClick" args="item">
109 alert("Execute of node " + this.model.getLabel(item)
110 +", population=" + continentStore.getValue(item, "population"));