这是我拉我的头发的东西。我正在尝试对项目进行分组,并根据日期对齐它们。我还将它们分组并计算,因此v.length,以显示销售的商品数量。
注意:我也在使用angular-filter作为groupBy
app.js
$scope.data = [
{ name: burger, category: food, date: 2-3-2015 },
{ name: burger, category: food, date: 2-4-2015 },
{ name: sandwich, category: food, date: 2-3-2015 },
{ name: sandwich, category: food, date: 2-4-2015 },
{ name: snacks, category: food, date: 2-4-2015 }
]
index.html
...
<tr ng-repeat="(key, value) in data | groupBy: 'name'">
<td>{{ key }}</td>
<td ng-repeat="(k, v) in value | groupBy: 'date'">
{{ v.length }}
</td>
</tr>
...
所以实际结果是:
| Item | 2-3-2015 | 2-4-2015 |
| burger | 1 | 1 |
| sandwich | 1 | 1 |
| snacks | 1 | |
但预期结果应为:
| Item | 2-3-2015 | 2-4-2015 |
| burger | 1 | 1 |
| sandwich | 1 | 1 |
| snacks | | 1 |
如何执行预期结果?