说我有以下数据结构
* Key 1
* Value 1
* Value 2
* Key 2
* Value 3
* Value 4
* Value 5
Run Code Online (Sandbox Code Playgroud)
如何使用AngularJS,我可以在类似于以下的表中呈现它:
|-------|---------|
| Key 1 | Value 1 |
| |---------|
| | Value 2 |
|-------|---------|
| Key 2 | Value 3 |
| |---------|
| | Value 4 |
| |---------|
| | Value 5 |
|-------|---------|
Run Code Online (Sandbox Code Playgroud)
钥匙通过rowspan
.
Jos*_*sep 38
好又棘手的问题!
一种方法是:
鉴于这样的对象:
$scope.testData={
key1:[1,2],
key2:[3,4,5]
};
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
<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>
Run Code Online (Sandbox Code Playgroud)