AngularJS重复表和rowspan

Jac*_*cob 22 angularjs

说我有以下数据结构

* 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)

  • @ user2195592哇!但这不是你在问题中描述的数据结构......这是另一个故事,让我看看它,请在接下来的几分钟保持联系. (2认同)