2012-09-22 59 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 
    }; 
});