我有以下
postCreate: function() {
this.items.forEach(lang.hitch(this, function(item) {
new SideNavigationItem({
name: item.name
}, this.container);
}));
}
将新的li
项目添加到ul
中,ul
模板具有一个附加点,我想将所有li
s构建到中 - 但是,在上述情况下,只需在迭代时创建下一个 li
的附件point的内容
有什么想法我该如何实现这一目标?
试试看。关键是使用_widgetBase placeat()方法,该方法的功能类似于DomConstructPloce()方法
Example
// place a new button as the first element of some div
var button = new Button({ label:"click" }).placeAt("wrapper","first");
如果您省略了第三个参数,就像我在下面的解决方案中所做的那样,默认位置是"最后",这是您想要的。
模板
<ul data-dojo-attach-point="myAttachPoint" >
<li>existing list item</li>
</ul>
javascript
this.items.forEach(lang.hitch(this, function(item) {
var listItem = new SideNavigationItem({name: item.name});
listItem.placeAt(this.myAttachPoint);
//if that doesn't work try it just with plain <li> item
//var listItem = domConstruct.toDom("<li></li>");
//domConstruct.place(listItem, this.myAttachPoint);
}));