[英]Create list items for array of objects
I have an array of objects: 我有一个对象数组:
myArray = [Object { orderNum="A000", userName="Oswaldo", value=504.74, more...}, Object { orderNum="A001", userName="Mao", value=529.17, more...}, Object { orderNum="A002", userName="Angeline", value=553.6, more...}, Object { orderNum="A003", userName="Gerardo", value=578.03, more...}]
I am trying to loop over it and get each object's contents into a list item. 我试图遍历它,并将每个对象的内容放入列表项。 I use this:
我用这个:
jQuery.each(Top5SalesOrders , function(index, value){
$('.mylist').append('<li>' + value + '</li>');
});
But I am getting [object Object] in my list items. 但是我在列表项中得到了[object Object]。
How can I solve this? 我该如何解决?
You are almost there, as second parameter of callback function is Object
, thus you have to use obj.value
to access the value
property of object. 回调函数的第二个参数是
Object
,您obj.value
了,因此您必须使用obj.value
来访问object的value
属性。
Use 采用
jQuery.each(Top5SalesOrders , function(index, obj){
$('.mylist').append('<li>' + obj.value+ '</li>');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.