1 | <html> |
---|
2 | <head> |
---|
3 | <title>Demo to show recursion in DTL</title> |
---|
4 | <script type="text/javascript" src="../../../dojo/dojo.js" |
---|
5 | djConfig="isDebug: true, parseOnLoad: true"></script> |
---|
6 | <script type="text/javascript"> |
---|
7 | dojo.require("dijit._WidgetBase"); |
---|
8 | dojo.require("dojox.dtl._DomTemplated"); |
---|
9 | dojo.require("dojo.data.ItemFileReadStore"); |
---|
10 | dojo.require("dojo.parser"); |
---|
11 | |
---|
12 | (function(){ |
---|
13 | var data = {}; |
---|
14 | |
---|
15 | // The only way to get ItemFileReadStore to work |
---|
16 | // synchronously (necessary for the bind_query format |
---|
17 | // we'll be using below) at the time of this writing |
---|
18 | // was to feed it data |
---|
19 | dojo.xhrGet({ |
---|
20 | url: dojo.moduleUrl("dijit.tests._data", "countries.json"), |
---|
21 | handleAs: "json", |
---|
22 | sync: true, |
---|
23 | load: function(json){ |
---|
24 | data = json; |
---|
25 | } |
---|
26 | }); |
---|
27 | |
---|
28 | dojo.declare("demo.Tree", [dijit._WidgetBase, dojox.dtl._DomTemplated], { |
---|
29 | constructor: function(){ |
---|
30 | this.disabled = {}; |
---|
31 | }, |
---|
32 | toggle: function(e){ |
---|
33 | var dataid = dojo.attr(e.target, "dataid"); |
---|
34 | this.disabled[dataid] = !this.disabled[dataid]; |
---|
35 | this.render(); |
---|
36 | }, |
---|
37 | store: new dojo.data.ItemFileReadStore({ data: data }), |
---|
38 | query: { type: "continent" }, |
---|
39 | templateString: '{% load dojox.dtl.contrib.objects %}{% load dojox.dtl.contrib.data %}{% bind_query query to store as countries %}<ul dojoAttachEvent="onclick: toggle">{% for country in countries %}{% include countrychildren %}{% endfor %}</ul>', |
---|
40 | countrychildren: '<li dataid="{{ country.getIdentity }}">{{ country.type }}: {{ country.name }}{% if country.children %}{% if disabled|key:country.getIdentity %} ↵{% else %}<ul>{% for country in country.children %}{% include countrychildren %}{% endfor %}</ul>{% endif %}{% endif %}</li>' |
---|
41 | }); |
---|
42 | })(); |
---|
43 | </script> |
---|
44 | </head> |
---|
45 | <body> |
---|
46 | <div dojoType="demo.Tree"></div> |
---|
47 | </body> |
---|
48 | </html> |
---|