我有一些代码:
$.getJSON(url, results => {
$('.search-output').html(`
<div class = "general">
${results.generalinfo.map( (item, index) => {
return `<h1>${item.title}</h1>`
})}
</div>
<div class = "profiles">
${$.each(results.profiles, function(index, item) {
return `<h1>${item.title}</h1>`
})}
</div> `)
})
使用.map()
功能,我可以得到所有想要的东西,但是$.each()
返回[object Object]
。我在$.each
函数中尝试过的内容:JSON.stringify
,.join()
最后-没有任何变化。此功能之间有什么区别?在这种情况下如何使用$.each()
?谢谢。
这是因为您要在tr上设置数据,然后用html填充它,但是仍然隐含一个对象,它将其转换为字符串... aka