dojo - Inherting dojox.mobile.View and using _TemplatedMixin -
goal: want create dojo widget separate template inherits dojox.mobile.view.
//javascript define([ "dojo/_base/declare", "dijit/_templatedmixin", "dijit/_widgetsintemplatemixin", "dojo/text!./templates/myappview.html", "dojox/mobile", "dojox/mobile/devicetheme", "dojox/mobile/compat", "require", "dojox/mobile/listitem", "dojox/mobile/heading"], function (declare, _templatedmixin, _widgetsintemplatemixin, template, mobile, devicetheme, compat, require) { return declare("widgets.myapp.myappview", [dojox.mobile.view, _templatedmixin, _widgetsintemplatemixin], { templatestring: template, widgetsintemplate: true, widgetbase: require.tourl("widgets/myapp/"), constructor: function (params) { params = params || {}; console.log("constructor" + dojo.tojson(params)); }, startup: function () { this.inherited(arguments); }, postcreate: function () { this.inherited(arguments); } }); });
template
<div> <div data-dojo-type="dojox/mobile/heading" data-dojo-props="label: 'templated view'"> </div> </div>
usage
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> <body> <script type="text/javascript" charset="utf-8" src="globals.js"></script> <script type="text/javascript" charset="utf-8" src="//ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"></script> <script type="text/javascript"> require([ "dojo/parser", "widgets/myapp/myappview", "dojo/domready", "dojox/mobile", "dojox/mobile/devicetheme", "dojox/mobile/compat" ], function (parser, myapp, ready) { parser.parse(); myapp = new widgets.myapp.myappview(); myapp.placeat("kj"); myapp.startup(); }); </script> <div id="kj"> </div> <!--crash--> <div data-dojo-type="widgets.myapp.myappview"> </div> </body> </html>
if create widget programmatically starts contains no template. if create <div data-dojo-type="widgets.myapp.myappview">
freezes.
if inherit dojox.mobile.view , in postcreate add other widgets programmatically works. however, in order keep structure maintainability need able both inherit dojox.mobile.view , able mixin template.
you didn't mention dojo version using. support templating view , other mobile widgets has been introduced in released dojo 1.9. if using older version, need upgrade.
useful resources available in 1.9:
- reference documentation of templating support in dojo mobile: templating mobile widgets.
- for example, can refer dojox/mobile/tests/test_templated-widgets.html (live version).
hope helps,
adrian
Comments
Post a Comment