加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS重复表和rowspan

发布时间:2020-12-17 07:42:43 所属栏目:安全 来源:网络整理
导读:说我有以下数据结构 * Key 1 * Value 1 * Value 2* Key 2 * Value 3 * Value 4 * Value 5 如何使用AngularJS,可以将其呈现在类似于以下内容的表格中: |-------|---------|| Key 1 | Value 1 || |---------|| | Value 2 ||-------|---------|| Key 2 | Value
说我有以下数据结构
* 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读