別のウィジェット内に dojo フォームがありますが、同じ JavaScript ファイル内にあります。フォームは dojoAttachPoint で定義されます。なので<form dojoType="dijit.form.Form" dojoAttachPoint="myForm">
ここで、同じ JavaScript 内および同じスーパー ウィジェット内の別のウィジェットからフォーム値にアクセスしたいと考えています。どうすればこれを達成できますか?
別のウィジェット内に dojo フォームがありますが、同じ JavaScript ファイル内にあります。フォームは dojoAttachPoint で定義されます。なので<form dojoType="dijit.form.Form" dojoAttachPoint="myForm">
ここで、同じ JavaScript 内および同じスーパー ウィジェット内の別のウィジェットからフォーム値にアクセスしたいと考えています。どうすればこれを達成できますか?
最初のウィジェット (兄弟にアクセスしたいウィジェット) 内から、次のことを試します。
// 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);