`

dojo中的DojoAttachPoint

    博客分类:
  • dojo
阅读更多
在 Dojo declaration 和 Dojo template 中,经常见到 dojoAttachPoint="xxx" 这种语句,经过查文档,终于有了些理性的认识。举例说明如下:
<thead dojoAttachPoint="head">
            <tr dojoAttachPoint="headRow"></tr>
</thead>

如果想在 js 中修改 thead 、tr 时,就可以通过 dojoAttachPoint 指定的别名 head , headRow 来引用到 thead , tr ,从而可以操作它。更深层地理解,就是 thead , tr 在页面的 DOM 树上分别对应着 DOM Node ,JS 操作 DOM 树时,要得到 DOM node 的实例时,才能对其进行操作。
比如在上面示例的表格中,要增加一个 td 结点时,就要得到 tr 的 instance,然后对其操作;在 JS 中实现的代码如下:

var tth = document.createElement("th");
this.headRow.appendChild(tth);

或者:

this.headRow.appendChild(document.createElement("td"));
其实和设置id,然后通过byId拿到dom节点也没有什么区别,只不过这样方面一点而已。oh oh
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics