如何使用嵌套的json访问orderId,如下所示
var user = [
{
'id',1
'order':[
{'orderId':12345},
{'orderId':654321}
]
},
{
'id',2
'order':[
{'orderId':3333},
{'orderId':4444}
]
}
]
我试过
<ul ng-repeat="user in user">
<li ng-repeat="order user.order">
{{order.orderId}}
</li>
</ul>
另外一个问题:ng-repeat仅用于对象json吗?
答案 0 :(得分:0)
<ul ng-repeat="user in user">
<li ng-repeat="order in user.order"> <!----- NEED TO ADD IN ---->
{{order.orderId}}
</li>
</ul>
我不认为它仅限于json,它只是通过数组重复。
对于语义,我会将您的JSON user
数组更改为users
:
var users = [ // <----------- see here
{
'id',1
'order':[
{'orderId':12345},
{'orderId':654321}
]
},
{
'id',2
'order':[
{'orderId':3333},
{'orderId':4444}
]
}
]