| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>latebinding</title> |
| 5 | <link type="text/css" href="../../../../dojo/resources/dojo.css" /> |
| 6 | <link type="text/css" href="../../../../dijit/themes/claro/claro.css" /> |
| 7 | <script src="../../../../dojo/dojo.js"></script> |
| 8 | <script> |
| 9 | var model; |
| 10 | require([ |
| 11 | 'dojo/_base/declare', |
| 12 | 'dojox/mvc', |
| 13 | 'dojox/mvc/Group', |
| 14 | 'dijit/_TemplatedMixin', |
| 15 | 'dijit/_WidgetsInTemplateMixin', |
| 16 | 'dojox/mvc/StatefulModel', |
| 17 | 'dojo/ready', |
| 18 | 'dojo/parser', |
| 19 | 'dijit/form/TextBox' |
| 20 | ], function (declare, mvc, Group, _TemplatedMixin, _WidgetsInTemplateMixin, StatefulModel, ready, parser, TextBox) { |
| 21 | declare('test.TextBox', [TextBox], { |
| 22 | startup: function () { |
| 23 | console.log('starting...', this.id, this.binding); |
| 24 | this.inherited(arguments); |
| 25 | console.log('started', this.id, this.binding); |
| 26 | } |
| 27 | }); |
| 28 | var testGroup = declare('test.Group', [Group], { |
| 29 | startup: function () { |
| 30 | console.log('starting...', this.id, this.binding); |
| 31 | this.inherited(arguments); |
| 32 | console.log('started', this.id, this.binding); |
| 33 | } |
| 34 | }); |
| 35 | declare('test.Templated', [testGroup, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 36 | templateString: '<div><input data-dojo-type="test.TextBox" data-dojo-props="ref: \'rel:fn\'"></div>' |
| 37 | }); |
| 38 | |
| 39 | model = new StatefulModel({ data: {fn: 'first', ln: 'last'}}); |
| 40 | ready(function () { |
| 41 | parser.parse(); |
| 42 | console.log('setting ref after parsing...'); |
| 43 | dijit.byId('late').set('ref', model); |
| 44 | var prog = new test.Templated({ |
| 45 | ref: model |
| 46 | }, 'prog'); |
| 47 | prog.startup(); |
| 48 | }); |
| 49 | }); |
| 50 | </script> |
| 51 | </head> |
| 52 | |
| 53 | <body class="claro"> |
| 54 | <h1>latebinding</h1> |
| 55 | <p>no template</p> |
| 56 | <div id="parsedGroup" data-dojo-type="test.Group" data-dojo-props="ref:model"> |
| 57 | <input data-dojo-type="test.TextBox" data-dojo-props="ref: 'rel:fn'" id="parsedInput"> |
| 58 | </div> |
| 59 | <p>Early parsed</p><div id="early" data-dojo-type="test.Templated" ref="model"></div> |
| 60 | <p>Late parsed</p><div id="late" data-dojo-type="test.Templated"></div> |
| 61 | <p>programmatic</p><div id="prog"></div> |
| 62 | </body> |
| 63 | </html> |