使用ng-repeat访问嵌套的json在我的情况下不起作用

时间:2014-04-17 11:19:20

标签: javascript angularjs

如何使用嵌套的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吗?

1 个答案:

答案 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}
               ]

    }
    ]