简体   繁体   English

嵌套json到ng-repeat无法正常工作

[英]nested json to ng-repeat doesn't working properly

App demo : http://jsfiddle.net/TR4WC/2/ 应用演示: http//jsfiddle.net/TR4WC/2/

am I missing something? 我错过了什么吗? I looped twice to access the 2nd array 我循环两次访问第二个数组

    <li ng-repeat="order in orders">
        <span ng-repeat="sales in order.sales>
    {{sales.salesId}}
</span>
</li>

one extra question : look like I can't do orderBy by salesId in my li because it have access only to the order array. 一个额外的问题:看起来我不能通过salesId在我的li中做订单,因为它只能访问订单数组。

This is silly but you are missing something, double quotes at the end of order.sales. 这很愚蠢,但你遗漏了一些东西,在order.sales末尾有双引号。

<div ng-controller="AppCtrl">
<li ng-repeat="order in orders">
    <span ng-repeat="sales in order.sales">
        {{sales.salesId}}
    </span>
</li>

That works for me. 这对我行得通。

EDIT: fork of your fiddle http://jsfiddle.net/6eXs6/ 编辑:小提琴的叉子http://jsfiddle.net/6eXs6/

In the Orders object sales isn't actually an array...it's an object where the key 'salesId' overwrites another 'salesId'. 在Orders对象中,sales实际上不是一个数组......它是一个对象,其中键'salesId'覆盖了另一个'salesId'。

I've replaced it with the following: 我用以下内容替换了它:

{
    'orderId': 1,
        'sales': [
            {'salesId': 1},
            {'salesId': 2}

    ]
}, 
{
    'orderId': 2,
        'sales': [
            {'salesId': 3},
            {'salesId': 4}

    ]
}

JSFiddle 的jsfiddle

You can't use the same name 'sales'. 您不能使用相同的名称'sales'。

Change: 更改:

<li ng-repeat="order in orders">
    <span ng-repeat="sale in order.sales">
        {{sale.salesId}}
    </span>
</li>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM