【发布时间】:2016-05-10 18:33:45
【问题描述】:
我不清楚如何在 dojo 中包含用于创建内容窗格的布局模块。我想在我的一个小部件中布局一些内容。
在 dojo takeit example 他们需要这些模块
require(["dojo/parser", "dijit/layout/BorderContainer", "dijit/layout/ContentPane"]);
但是我想包含这个的小部件是这样的
define([
"dojo/_base/declare",
"dojo/parser",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!./home/templates/HomePage.html",
"xstyle/css!./home/css/HomePage.css",
"dijit/layout/LayoutContainer",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane"
], function (
declare,
parser,
_WidgetBase,
_TemplatedMixin,
_WidgetsInTemplateMixin,
template,
css,
lc,
bc,
cp
) {
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: template,
postCreate: function () {
this.inherited(arguments);
},
startup: function () {
this.inherited(arguments);
}
});
});
而小部件 HTML 是这样的
<div style="width: 100%; height: 100%;">
<div data-dojo-type="dijit/layout/BorderContainer" style="width: 100%; height: 100%">
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'">Top pane</div>
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'leading'">Leading pane</div>
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">Center pane</div>
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'trailing'">Trailing pane</div>
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'bottom'">Bottom pane</div>
</div>
</div>
但它不起作用,即使我包含了这些依赖项
"dijit/layout/LayoutContainer",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane"
在哪里放置所需的模块以便在我的自定义模板小部件中使用布局小部件?还是我错过了什么?
编辑:通过将 require 放在定义上方,我能够使用此代码使其工作
require(["dojo/parser", "dijit/layout/ContentPane", "dijit/layout/BorderContainer"]);
require(["dojo/parser", "dojo/ready"], function (parser, ready) {
ready(function () {
parser.parse();
});
});
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!./home/templates/HomePage.html",
"xstyle/css!./home/css/HomePage.css",
"./home/HomeNavigationWidget"
], function (
declare,
_WidgetBase,
_TemplatedMixin,
_WidgetsInTemplateMixin,
template,
css,
HomeNavigationWidget
) {
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: template
});
});
编辑:我发现布局之所以起作用是因为_WidgetsInTemplateMixin。添加它允许在模板内使用布局小部件。我删除了定义上方的两个 require 语句,它工作正常。在 dojoConfig 中,parseOnLoad 设置为 false。
【问题讨论】:
标签: dojo