【发布时间】:2015-07-24 10:50:25
【问题描述】:
我有一个包含 json 数据的电话数组:
var phones = [
{
"age": 0,
"id": "motorola-xoom-with-wi-fi",
"imageUrl": "img/phones/motorola-xoom-with-wi-fi.0.jpg",
"name": "Motorola XOOM\u2122 with Wi-Fi",
"snippet": "The Next, Next Generation\r\n\r\nExperience the future with Motorola XOOM with Wi-Fi, the world's first tablet powered by Android 3.0 (Honeycomb)."
},
我编写了代码来将该数组显示为列表 ul li:
function createList_Task_4(){
$.each(phones, function(i, phone){
phones.push("<li>" + phone.age +"</li><br><li>" + phone.id +
"</li><br><img src='" + phone.imageUrl + "'/></li><br><li>" + phone.name + "</li><br><li>" + phone.snippet +"</li>" );
});
$('#phonesList').append(phones.join(''));
}
它显示我想要的数据,但它显示在列表的顶部:
[object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object]
<ul>
<li>0</li>
<li>motorola-xoom-with-wi-fi</li>
<ul/>
如何删除这个[object Object]?
【问题讨论】:
-
您的
phones是一个对象数组!你需要什么?将li直接附加到$('#phonesList'),而不是将其推送到phones。 -
为什么
<br>在<li>s 之间?
标签: javascript jquery html css arrays