如果你用dijit._Container擴展你的父項,你可以通過調用parent.getChildren()
來獲得你的控件集。小部件返回的順序是它們添加到父項(parent.addChild()
)而不是DOM兄弟機構的順序。但是,一旦你使用解析器,這個ofc將是相同的。那麼,任何小部件都會實現getChildren,但_Container類的區別在於,addChild: function(/*dijit._Widget*/ widget, /*int?*/ insertIndex)
和removeChild: function(/*Widget|int*/ widget)
函數非常漂亮。如果在添加子級時插入insertIndex,則兄弟會引擎可管理。
對於domNodes的關注,使用dijit我們會'超越'DOM並且在widget層中工作 - 而這只是一個JS包裝。該環連接的功能「.domNodes()」不隨地道場存在,而不是你需要調用類似以下內容:
parent.getChildren().forEach(function(childWidget) {
var domNode = childWidget.domNode;
...
});
// this would get nowhere as the return child-set is merely a 'stupid' array
parent.getChildren().set("attribute", "value");
這裏是上面的foreach一個可愛的小包裝,使用的dijit /圖
// retreives an array of the actual domNodes of widgetset
dijit.registry.map(function(widget){return widget.domNode;}).forEach(
// uses hitch to allow passing parameters without wrapping in new function
dojo.hitch(
window, // on random scope
dojo.addClass, // calling function
"imTheChildDomNode"// arguments[0]
)
);