我也用dojo 样板项目 https://github.com/csnover/dojo-boilerplate对于我的应用程序,这是我的main.js
:
define([ 'dojo/has', 'require', 'dojo/_base/sniff' ], function (has, require) {
var app = {};
if (has('host-browser') && isCompatible()) {
require([ './EntryPoint', 'dojo/domReady!' ], function (EntryPoint) {
app.entryPoint = new EntryPoint().placeAt(document.body);
app.entryPoint.startup();
} else {
window.location = "/admin/browser/";
}
function isCompatible() {
// browser compatibility check here
}
});
My EntryPoint
模块/类是一个小部件,即EntryPoint.js
好像:
define([
"dojo/_base/declare",
"dijit/_Widget",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/i18n!app/nls/main",
"dojo/text!./ui/templates/EntryPoint.html",
"dijit/layout/BorderContainer",
"dijit/layout/StackContainer",
"dijit/layout/ContentPane"
], function(
declare,
_Widget,
_TemplatedMixin,
_WidgetsInTemplateMixin,
i18n,
template
){
return declare([_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: template,
i18n: i18n,
postCreate: function() {
//...
}
});
});
最后我的EntryPoint.html
:
<div style="height:100%;">
<div
data-dojo-type="dijit.layout.BorderContainer"
data-dojo-props="design: 'sidebar', gutters: false"
data-dojo-attach-point="mainContainer"
style="height:100%;"
>
<div
data-dojo-type="dijit.layout.BorderContainer"
data-dojo-props="region: 'left', splitter: true, design: 'headline', gutters: false"
data-dojo-attach-point="sidebarPane"
class="sidebarPane"
>
<div
data-dojo-type="dijit.layout.ContentPane"
data-dojo-props="region: 'center'"
>
<div class="sidebarSection">${i18n.title.public_}</div>
<div
id="sidebar-posts"
data-dojo-type="app.widget.SidebarItem"
data-dojo-props="iconClass: 'sidebarIconPosts', value:'posts', name: 'sidebar'">
${i18n.title.posts}
</div>
<div
id="sidebar-pages"
data-dojo-type="app.widget.SidebarItem"
data-dojo-props="iconClass: 'sidebarIconPages', value:'pages', name: 'sidebar'">
${i18n.title.pages}
</div>
[...]
使用的优点Widget
作为您的主要布局:
- html 模板可以与 dojo 构建系统一起使用
- 您可以使用
data-dojo-attach-point
and data-dojo-attach-event
在您的布局模板中
- 您可以使用
${i18n.title.members}
用于 html 中的字符串替换