ng-repeat嵌套循环

时间:2016-05-03 09:18:10

标签: angularjs ionic-framework

我循环浏览数组并使用过滤器分隔按天分组的结果。它有效,但现在我似乎无法访问第二个循环中的变量,我有过滤器。

<ion-list class="list list-inset"  ng-repeat="(key, value) in Jobs | groupBy: 'FilterTime'">
    <div class="item item-divider"><center>{{key}}</center></div>

    <div class="list list-inset" >
        <div class="item item-divider"><center>{{JobCount}} jobs</center></div>

        <a class="item item-icon-left item-icon-right" href="#/app/viewjob/{{job.BookingPublicId}}" ng-repeat="job in value  | groupBy: 'BookingTime'">
            <i class="icon ion-android-car "></i>
            <h2>{{job.EndAddress1stLine}}</h2>
            <p>{{job.StartAddressPostCode}} <b>></b> {{job.EndAddressPostCode}}</p>

            <p ng-show="job.Status == 0"><b>Waiting</b> - {{job.BookingTime * 1000 | date:'dd-MM-yyyy hh:mm'}}</p>
            <p ng-show="job.Status == 2"><b>Accepted</b> - {{job.BookingTime * 1000 | date:'dd-MM-yyyy hh:mm'}}</p>
            <p ng-show="job.Status == 4"><b>Enroute to job</b> - {{job.BookingTime * 1000 | date:'dd-MM-yyyy hh:mm'}}</p>
            <p ng-show="job.Status == 6"><b>Waiting for customer</b> - {{job.BookingTime * 1000 | date:'dd-MM-yyyy hh:mm'}}</p>
            <p ng-show="job.Status == 8"><b>Job Started</b> - {{job.BookingTime * 1000 | date:'dd-MM-yyyy hh:mm'}}</p>
            <p ng-show="job.Status == 10"><b>Complete</b> - {{job.BookingTime * 1000 | date:'dd-MM-yyyy hh:mm'}}</p>
            <!--<span class="item-note">{{job.StartAddressPostCode}} > {{job.EndAddressPostCode}}</span>-->
            <i class="icon ion-chevron-right "></i>
        </a>
    </div>
    <!--<p>{{value.BookingPublicId}} <b>></b> {{EndAddressPostCode}}</p>-->
</ion-list>

现在,job.variable中的任何内容都无法加载,但如果我只是工作,它会吐出所有json。

enter image description here

正如您所看到的,分组工作;但我看不到任何数据。如果我吐出工作,我会得到这个:

enter image description here

编辑:数据如下:

[
{
"BookingPublicId": "C1LY482T",
"BookingTime": 1462238100,
"FilterTime": "03/05/2016",
"BookingName": "",
"Status": 1,
"PassengersName": "John Smith",
"PassengersMobile": null,
"Fare": "544.13",
"StartAddressPostCode": "RG2 0GH",
"StartAddress1stLine": "Drake Way",
"EndAddressPostCode": "M90 1QX",
"EndAddress1stLine": "Drake Way",
"Status1": 1,
"Resp": "OK"
},
{
"BookingPublicId": "ZGX39WNB",
"BookingTime": 1462268100,
"FilterTime": "03/05/2016",
"BookingName": "",
"Status": 1,
"PassengersName": "John Smith",
"PassengersMobile": null,
"Fare": "544.13",
"StartAddressPostCode": "RG2 0GH",
"StartAddress1stLine": "Drake Way",
"EndAddressPostCode": "M90 1QX",
"EndAddress1stLine": "Drake Way",
"Status1": 1,
"Resp": "OK"
}
]

1 个答案:

答案 0 :(得分:2)

从第二张图片看来,job是一个数组而不是一个对象,因此job.EndAddress1stLine无效。

如果您的job只包含一个对象,则可以使用(job[0]).EndAddress1stLine之类的内容。 (这也意味着你的数据结构可能有问题。如果你有可能只获得一个对象,你应该再看一遍)

如果它包含多个对象,则需要(如评论中所述)另一个ng-repeat超过job