在父数据之间使用嵌套的ng-repeat进行ng-repeat

时间:2017-05-08 21:14:50

标签: angularjs angularjs-ng-repeat

我有一个带有球员阵列的对象数组。我希望在表格行中显示信息,但在行的中间使用嵌套数组的值。除了最后一栏,我得到了所有信息。它空白,告诉我它是一个无效的密钥。

<table class="table table-condensed table-striped"ng-show="vm.registrations.length > 0">
    <thead>
        <td>Day</td>
        <td>Field</td>
        <td>Event</td>
        <td colspan="4">Players</td>
        <td>Status</td>
    </thead>
    <tbody>
        <tr ng-repeat="event in vm.registrations" >
        <td>{{event.day}}</td>
        <td>{{event.field | uppercase }}</td>
        <td>{{event.event}}</td>
        <td colspan="4" ng-if="event.numplayers == 2">
            <span ng-repeat="player in event.players">
              <span>{{player.first}} {{player.last}}</span>
              <span ng-show="$last">, </span>
            </span>
        </td>
        <td>
            <span class="label label-sucess" ng-if="{{event.active}} == true">ACTIVE</span>
            <span class="label label-danger" ng-if="{{event.active}} == false">Canceled</span>
        </td>
        </tr>
    </tbody>
</table>

数据应该显示为(但最后一列是空白的,但标题除外):

Day     Field     Event      Players     Status
Sat     MAIN      Mens B     Bob, John   Active
Sun     COED      COED A     Bob, Mary   Canceled

这就是我得到的:

Day     Field     Event      Players     Status
Sat     MAIN      Mens B     Bob, John   
Sun     COED      COED A     Bob, Mary   

如何返回父ng-repeat完成显示?

1 个答案:

答案 0 :(得分:2)

错误

 <span ng-show"$last">

你忘了等于

 <span ng-show="$last">

这就是为什么你没有看到ng-repeat的最后一个元素