说我有以下数据结构
* Key 1
* Value 1
* Value 2
* Key 2
* Value 3
* Value 4
* Value 5
如何使用AngularJS,可以将其呈现在类似于以下内容的表格中:
|-------|---------| | Key 1 | Value 1 | | |---------| | | Value 2 | |-------|---------| | Key 2 | Value 3 | | |---------| | | Value 4 | | |---------| | | Value 5 | |-------|---------|
密钥是通过rowspan完成的.
尼斯和棘手的问题!
一种方法是:
给出一个这样的对象:
$scope.testData={
key1:[1,2],key2:[3,4,5]
};
你可以这样做:
<table>
<tr ng-repeat-start="(key,val) in testData">
<td rowspan="{{val.length}}">{{key}}</td>
<td>{{val[0]}}</td>
</tr>
<tr ng-repeat-end ng-repeat="value in val.slice(1)">
<td>{{value}}</td>
</tr>
</table>
Example