因此,我在名为“MainController”的控制器中定义了以下对象的javascript集合:
$scope.records = [
{
id: 100,
name: 'Item Shipping 100',
minute: 7
},
{
id: 101,
name: 'Item Shipping 101',
minute: 9
},
{
id: 102,
name: 'Item Shipping 102',
minute: 15
}
];
我想在每个单元格中将此集合绑定到一个HTML表,范围为10分钟:
0 - 9
10 - 19
20 - 29
30 - 39
40 - 49
50 - 59
每个单元格代表一个10分钟的范围,在每个单元格中,我只想显示属于单元格中每个范围的记录集合中的项目,这就是我现在的做法,是否有更好的方法来做到这一点?我问的原因是我有很多行要添加,我不想重复这段代码很多次,也许有更好的方法来绑定它。
<div ng-controller="MainController">
<table class="table">
<thead>
<tr>
<th>0 - 9</th>
<th>10 - 19</th>
<th>20 - 29</th>
<th>30 - 39</th>
<th>40 - 49</th>
<th>50 - 59</th>
</tr>
</thead>
<tbody>
<tr class="even-row">
<td>
<div class="record" ng-repeat="item in records" ng-if="item.minute >= 0 && item.minute <= 9">
<div>{{ item.id }}</div>
<div>{{ item.name }}</div>
</div>
</td>
<td>
<div class="record" ng-repeat="item in records" ng-if="item.minute >= 10 && item.minute <= 19">
<div>{{ item.id }}</div>
<div>{{ item.name }}</div>
</div>
</td>
<td>
<div class="record" ng-repeat="item in records" ng-if="item.minute >= 20 && item.minute <= 29">
<div>{{ item.id }}</div>
<div>{{ item.name }}</div>
</div>
</td>
<td>
<div class="record" ng-repeat="item in records" ng-if="item.minute >= 30 && item.minute <= 39">
<div>{{ item.id }}</div>
<div>{{ item.name }}</div>
</div>
</td>
<td>
<div class="record" ng-repeat="item in records" ng-if="item.minute >= 40 && item.minute <= 49">
<div>{{ item.id }}</div>
<div>{{ item.name }}</div>
</div>
</td>
<td>
<div class="record" ng-repeat="item in records" ng-if="item.minute >= 50 && item.minute <= 59">
<div>{{ item.id }}</div>
<div>{{ item.name }}</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
谢谢您!