在使用AngularJS渲染表格时,是否可以按照 这里所述的方式对数据进行分组(使用rowspan)?数据具有层次结构,state
拥有多个counties
,每个county
又有多个zipcodes
。我希望得到一个只包含州、县、邮政编码等列的表格(因此要为集合的长度设置rowspan)。我不确定是否可以使用ng-repeat-start
和ng-repeat-end
来实现这一点。请参阅起始模板此处。
<table>
<thead>
<tr>
<th>State</th>
<th>County</th>
<th>Zip</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='st in states'>
<td>{{st.name}}</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
数据
var oh_counties = [
{name: "Franklin", zips: [111,222,333,444,555]},
{name: "Adams", zips: [111,222,333,444]},
{name: "Allen", zips: [111,222,333]}
],
wi_counties = [
{name: "Dane", zips: [111]},
{name: "Adams", zips: [111,222,333,444]}
]
$scope.states = [
{name: "OH", counties: oh_counties},
{name: "WI", counties: wi_counties},
];
编辑:
这里提供了一个手工制作的期望输出版本,链接如下:http://plnkr.co/edit/T7toND0odx6qr8mVC121?p=preview