Dojo从另一个小部件访问表单值

时间:2013-09-17 16:41:55

标签: dojo

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

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

1 个答案:

答案 0 :(得分:0)

从第一个Widget(想要访问其兄弟姐妹的那个)中我尝试:

// 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);
相关问题