0

我在另一个小部件内有 dojo 表单,但在同一个 javascript 文件中。表单是用dojoAttachPoint 定义的。作为<form dojoType="dijit.form.Form" dojoAttachPoint="myForm">

现在我想从同一个 javascript 和同一个超级小部件内的另一个小部件访问表单值。我怎样才能做到这一点?

4

1 回答 1

0

从第一个小部件(想要访问其兄弟的那个)中,我会尝试:

// Using the dijit/registry module
var parentWidget = registry.getEnclosingWidget(this.domNode);

// Assuming the parent has the other sibling as an attachpoint, 
// but could be some other accessor or variable
var siblingWidget = parentWidget.secondSiblingAttachPoint; 

// Simple enough from here
var targetForm = siblingWidget.myForm;

这有点“又快又脏”,所以如果需要在很多地方重用该模式,我宁愿做其他事情,例如让父小部件“注入”这样的引用:

this.myFirstChild.setForm(this.mySecondChild.myForm);
于 2013-09-17T17:57:20.107 回答