我在使用 Dojo 的加载程序时遇到了真正的问题。我发现在这里粘贴代码真的很困难,因为这是一个涉及整个应用程序的问题。我创建了一个名为的小部件LoginForm
,它的开头如下:
define([
"dojo/_base/declare",
"app/globals",
"app/stores",
"dijit/form/Form",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dijit/layout/TabContainer",
"dijit/layout/StackContainer",
"dijit/layout/ContentPane",
"dijit/layout/BorderContainer",
"dijit/form/Button",
"app/widgets/ValidationPassword",
"app/widgets/ValidationEmail",
"app/widgets/AlertBar",
"app/widgets/StackFading",
"app/widgets/TabFading",
"dojo/_base/lang",
"app/widgets/BusyButton",
"dojo/_base/json",
"dojo/_base/fx",
"dojo/text!app/widgets/templates/LoginForm.html",
], function(
declare,
...
, json
, baseFx
, templateString
){
// Create the "login" pane, based on a normal ContentPane
return declare('app.LoginForm', [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin ], {
widgetsInTemplate: true,
templateString: templateString,
这是一个使用模板的简单小部件,在模板中还有一些子小部件,如此处所述。
现在......我正在尝试在 Ajax 回调中创建一个 Loginform 类型的对象。然而,装载机让我失望了。
应用程序的主屏幕如下所示:
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"app/widgets/Dashboard",
"app/globals",
"dijit/layout/BorderContainer",
"dijit/layout/StackContainer",
"dijit/layout/TabContainer",
"dijit/layout/ContentPane",
"app/widgets/SearchPage",
], function(
declare
, _WidgetBase
...
, SearchPage
){
// Create the "login" pane, based on a normal ContentPane
return declare('AppMainScreen', [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin ], {
...
第三个小部件 Dashboard 只有一个按钮:
define([
"dojo/_base/declare",
"app/globals",
"app/defaultSubmit",
"app/stores",
"dijit/form/Form",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"app/widgets/AlertBar",
"app/widgets/BusyButton",
"dojo/_base/json",
"dojo/domReady!",
], function(
declare
, g
, ds
, stores
, Form
, _WidgetBase
, _TemplatedMixin
, _WidgetsInTemplateMixin
, AlertBar
, BusyButton
, json
){
// Create the "login" pane, based on a normal ContentPane
return declare('app.Dashboard', [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin ], {
widgetsInTemplate: true,
templateString: '' +
'<div>' +
' <div data-dojo-type="app.AlertBar" data-dojo-attach-point="alertBar"></div>' +
' <form data-dojo-type="dijit.form.Form" data-dojo-attach-point="form" method="POST"> ' +
' <input type="submit" data-dojo-attach-point="button" data-dojo-type="app.BusyButton" label="Create!" />' +
' </form>' +
'</div>',
该表单的 onSubmit 然后链接到一个函数,"app/defaultSubmit",
其中读取:
define([
'app/globals',
'dijit/registry',
'dojo/query',
'dojo/aspect',
'dojo/_base/lang',
'dojo/_base/json',
'dijit/Tooltip',
'dijit/Dialog',
'app/widgets/LoginForm',
],function(
g
, registry
, query
, aspect
, lang
, json
, Tooltip
, Dialog
, LoginForm
){
问题是 LoginForm 不起作用,因为 LoginForm 的构造函数不起作用:它说它不能实例化依赖类之一。
现在,如果我将此添加到应用程序的 mainScreen 的 postCreate:
var loginForm = new LoginForm({});
然后,在回调中,LoginForm() 神奇地工作(!)。
我知道我没有发布所有代码,但是就 AMD 中如何处理依赖项而言,我需要了解什么魔法吗?如何确保在回调中解析模块...?
再见,
默克。