gpt4 book ai didi

javascript - 将新小部件推送到 DOJO 连接点而不是替换

转载 作者:太空宇宙 更新时间:2023-11-04 16:17:05 25 4
gpt4 key购买 nike

我有以下内容

    postCreate: function() {
this.items.forEach(lang.hitch(this, function(item) {
new SideNavigationItem({
name: item.name
}, this.container);
}));
}

这增加了一个新的 li项目到 ulul模板有一个附加点,我想构建所有 li s into - 但是执行上述操作只会将附加点的内容替换为下一个 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);
}));

关于javascript - 将新小部件推送到 DOJO 连接点而不是替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40997608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com