AngularJs - 在表的td中重复集合的集合

时间:2016-03-20 22:37:34

标签: arrays angularjs angularjs-ng-repeat ng-repeat

通过AngularJS(ng-repeat),我会在html表的td上使用列表列表。

控制器中的数据:

$scope.schedules = [{plage:'8-12'},{plage:'14-18'},{plage:'19-23'}];
$scope.days = [{day:'Monday',schedules:$scope.schedules},{day:'Tuesday',schedules:$scope.schedules},{day:'Wednesday',schedules:$scope.schedules},{day:'Thursday',schedules:$scope.schedules},{day:'Friday',schedules:$scope.schedules}];

我想要2行(第1天=第2天=第2周期):



<table>
  <tr>
    <td>Days:</td>
    <td colspan="3">Monday</td>
    <td colspan="3">Tuesday</td>
    <td colspan="3">Wednesday</td>
    <td colspan="3">Thursday</td>
    <td colspan="3">Friday</td>
  </tr>
  <tr>
    <td class="week">Schedules:</td>
    <td>8-12</td><td>14-18</td><td>19-23</td>
    <td>8-12</td><td>14-18</td><td>19-23</td>
    <td>8-12</td><td>14-18</td><td>19-23</td>
    <td>8-12</td><td>14-18</td><td>19-23</td>
    <td>8-12</td><td>14-18</td><td>19-23</td>
  </tr>
</table>
&#13;
&#13;
&#13;

HTML中的

<table>
    <tr>
        <td>Days:</td>
        <td ng-repeat="businessWeekDay in days" colspan="3">{{businessWeekDay.day}}</td>
    </tr>
    <tr>
        <td>Schedule:</td>
        <!-- "businessWeekDay in days" -->
        <!-- "schedule in businessWeekDay.schedules"-->
        <td ng-repeat="?????????????">{{schedule.plage}}</td>
    </tr>
</table>

1 个答案:

答案 0 :(得分:3)

展平时间表,并使用单个ng-repeat:

var allSchedules = [];
$scope.days.forEach(function(day) {
    Array.prototype.push.apply(allSchedules, day.schedules);
});

在视图中:

<td ng-repeat="schedule in allSchedules">{{ schedule.plage }}</td>