我试图用jQuery显示数组中的项目,但它只是返回[object] [Object]
。我在这里做错了什么?
以这种格式返回数据:
Object
1:{gps: "0.000,0.000", street_name: "First Street", street_name_alt: "1st Street"}
2:{gps: "0.000,0.000", street_name: "Second Street", street_name_alt: "2nd Street"}
我正在尝试输出:
$.each( data.street, function( key, val ) {
htm+='<ons-list-item id="'+key+'">';
htm+=' '+val;
htm+='</ons-list-item>';
});
答案 0 :(得分:2)
val
是您的对象,关键是索引..
您必须尝试访问它的属性。如需访问street_name
$.each( data.street, function( key, val ) {
htm+='<ons-list-item id="'+key+'">';
htm+=' '+val.street_name;
htm+='</ons-list-item>';
});
它不是多维数组btw,它是一个嵌套对象。
答案 1 :(得分:0)
Debug.Print con.Name & " - " & con.Properties("AggregateType").Value
data = {};
data.street = [{gps: "0.000,0.000", street_name: "First Street", street_name_alt: "1st Street"},
{gps: "0.000,0.000", street_name: "Second Street", street_name_alt: "2nd Street"}];
var htm = "";
// updated the arguments to reflect their functions better.
$.each( data.street, function( index, element ) {
htm+='<ons-list-item id="'+index+'">';
htm+=' '+element .street_name;
htm+='</ons-list-item>';
});
console.log(htm);
那是因为<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
指的是完整的对象。使用属性名称来获得正确的结果。