从模板文件(DOJO)中的嵌套元素访问自定义小部件
我对dijit小部件和小部件内部的小部件有一个有趣的问题。我创建了一个自定义小部件,其中包含一个带有表单的dijit.dialog。这是一个样本从模板文件(DOJO)中的嵌套元素访问自定义小部件,dojo,Dojo,我对dijit小部件和小部件内部的小部件有一个有趣的问题。我创建了一个自定义小部件,其中包含一个带有表单的dijit.dialog。这是一个样本 <div dojoattachpoint="WorkinProgress"> <div dojoType="dijit.Dialog" id="formDialog" title="Agent Note" > <table> <tr> <td>
<div dojoattachpoint="WorkinProgress">
<div dojoType="dijit.Dialog" id="formDialog" title="Agent Note" >
<table>
<tr>
<td>
<label for="desc">
Description:
</label>
</td>
<td>
<input dojoType="dijit.form.Textarea" style="width:400px" type="text" name="desc" id="desc">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<button dojoType="dijit.form.Button" type="submit" dojoattachevent="onclick: createNote >
SAVE
</button>
<button dojoType="dijit.form.Button" type="button" onClick="dijit.byId('formDialog').hide();">
CLOSE
</button>
</td>
</tr>
</table>
说明:
为什么不给按钮、对话框和最外面的小部件dojoAttachPoint属性,然后在自定义小部件的postCreate功能中执行以下操作:
dojo.connect(this.createNoteButton, "onclick", this, this._createNoteHandler);
然后在自定义小部件上创建一个名为“\u createNoteHandler”的函数,并执行需要执行的操作。
这种方法的优点是,对于一个事件的多个处理程序,您可以使用pub/sub而不是dojo.connect,您可以更好地控制交互,您不会在标记中乱放可能更改的函数名称(更好地分离关注点)…。如果您动态添加子小部件,尝试使用dijit.\u Widget.placeAt函数将DOM节点包含在内。显然,只需将HTML字符串添加到父窗口小部件中,只会添加子窗口小部件的根DOM(在您的示例中,是第二个div)。完成此操作后,您应该能够从dojoAttachPoint等获取父级信息