gpt4 book ai didi

method-chaining - 链接 jQuery.each()

转载 作者:行者123 更新时间:2023-12-01 00:11:12 25 4
gpt4 key购买 nike

我正在尝试将对象的结果添加到新创建的 HTML 元素中:

*long chain of newly created elements*.append(
$("<div />").append(
$.each(myObj.results, function( intIndex, objValue ){
return objValue.description;
})
)
);

如果我使用带有for循环的function()调用而不是each(),它可以工作,但是没有办法用each()来实现这一点吗?

最佳答案

.each 只是遍历一个集合,您需要一个匿名函数来返回一些内容,所以试试这个:

$("<div />").append(function(){
var string = "":
$.each(myObj.results, function( intIndex, objValue ){
string += objValue.description;
})
return string;
});

关于method-chaining - 链接 jQuery.each(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11116370/

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