将新小部件推送到 DOJO 附加点而不是替换
Push new widget to DOJO attach point not replace
我有以下
postCreate: function() {
this.items.forEach(lang.hitch(this, function(item) {
new SideNavigationItem({
name: item.name
}, this.container);
}));
}
将新的 li
项添加到 ul
,ul
模板有一个附加点,我想将所有 li
构建到 -但是,执行上述操作只是将附加点的内容替换为迭代时创建的下一个 li
有什么想法可以实现这一目标吗?
试试这个。关键是使用 _WidgetBase placeAt() 方法,其功能类似于 domConstruct place() 方法
Example
// place a new button as the first element of some div
var button = new Button({ label:"click" }).placeAt("wrapper","first");
如果你省略第三个参数,就像我在下面的解决方案中所做的那样,默认位置是 'last',这就是你想要的。
模板
<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);
}));
我有以下
postCreate: function() {
this.items.forEach(lang.hitch(this, function(item) {
new SideNavigationItem({
name: item.name
}, this.container);
}));
}
将新的 li
项添加到 ul
,ul
模板有一个附加点,我想将所有 li
构建到 -但是,执行上述操作只是将附加点的内容替换为迭代时创建的下一个 li
有什么想法可以实现这一目标吗?
试试这个。关键是使用 _WidgetBase placeAt() 方法,其功能类似于 domConstruct place() 方法
Example
// place a new button as the first element of some div
var button = new Button({ label:"click" }).placeAt("wrapper","first");
如果你省略第三个参数,就像我在下面的解决方案中所做的那样,默认位置是 'last',这就是你想要的。
模板
<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);
}));