jQuery 每个返回 [object Object] [英] jQuery each returns [object Object]

查看:59
本文介绍了jQuery 每个返回 [object Object]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是 html 变量返回如下内容:[object Object][object Object][object Object][object Object][object Object],而不是元素.

My problem is that the html variable returns something like this: [object Object][object Object][object Object][object Object][object Object], instead of the elements.

我应该怎么做?

var html = '';
$.each(data.response, function(index, value) { 
    var tr = $('<tr>');
    var tr_data = '<td>asd</td>';
    html += tr.data('trackinfo',value).html(tr_data);   
});

$(target).html(html);

推荐答案

那是因为你在 tr 上设置数据,然后用你的 html 填充它,但仍然连接一个对象,它将其转换为字符串...又名

That's because you're setting the data on the tr and then filling it with your html, but still concatinating an object, which converts it to a string... aka

"[object Object]"

不完全确定你想要什么,但你可以尝试改变它...

Not exactly sure what you're after but you might try changing this...

html += tr.data('trackinfo',value).html(tr_data);   

为此...

html += tr.data('trackinfo',value).html(tr_data).html();   

这篇关于jQuery 每个返回 [object Object]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆