2012-09-22 41 views
0

我是dojo的新手。我已经定义了一个小部件,如果看起来像这样:Dojo Toolkit中定义的参数

define(["dojo/_base/declare", "dijit/_Widget", "dijit/_TemplatedMixin", "dojo/text!Widgets/Templates/Screen.html", "./Node", "dojo/_base/array", "dojo/dom-geometry", "dojo/dom-style"], 
    function (declare, widget, templated, template, node, array, domGeometry, domStyle) { 
... 

我不知道这是怎么回事。我有这么长的需求清单还是需要在回调中需要它们?

回答

0

这不是一个特别长的模块列表。 Dojo将其功能分解为相当小的模块,因此很多时候都会提取其中的很多模块。

你肯定不希望在回调中要求他们。 definerequire基本相同,但在模块的顶部用于声明具有依赖关系的异步模块的结果。

有一件值得注意的事情是,可能值得向具有相同或相似名称的参数注入类依赖关系:它使结果declare调用更简单,例如,

define(["dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/text!mytemplate.html"], function(declare, _WidgetBase, _TemplatedMixin, template) { 

    return declare("my.Widget", [_WidgetBase, _TemplatedMixin], { 
     templateString: template 
    }; 
}); 

您也可能希望将您的依赖关系组合为逻辑组,例如,把你的基类放在一起,将辅助模块放在一起。您还需要声明模板中提到的其他模块,位于模块列表的,如果您未在代码中使用它们,则不一定需要将它们声明为回调参数,例如used/by/template1 and used/by/template2 here:

define(["dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/text!mytemplate.html", "used/by/template1", "used/by/template2"], function(declare, _WidgetBase, _TemplatedMixin, template) { 

    return declare("my.Widget", [_WidgetBase, _TemplatedMixin], { 
     templateString: template 
    }; 
});