$。每个返回[object Object],而.map()正确执行

问题描述 投票:-1回答:1

我有一些代码:

$.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()?谢谢。

jquery each
1个回答
0
投票

这是因为您要在tr上设置数据,然后用html填充它,但是仍然隐含一个对象,它将其转换为字符串... aka

© www.soinside.com 2019 - 2024. All rights reserved.