Skip to content

angular ng repeat start

遇见王斌 edited this page Mar 26, 2020 · 1 revision

ng-repeat-start

使用 ng-rapeat-start 与 ng-rapeat-end 指令进行合并单元格

后台返回的数据是这样的,要求返回的数据是一个数组,而每一个数组里面包含了,合并的列以及一个数组,结构如下:

var data = [
    {
        "nian": "一年级",
        "item": [
            {
                "name": "张三",
                "age": "23"
            },
            {
                "name": "张三",
                "age": "23"
            }
        ]
    },
    {
        "nian": "二年级",
        "item": [
            {
                "name": "张三",
                "age": "23"
            },
            {
                "name": "张三",
                "age": "23"
            }
        ]
    },
    {
        "nian": "三年级",
        "item": [
            {
                "name": "张三",
                "age": "23"
            },
            {
                "name": "张三",
                "age": "23"
            }
        ]
    }
];

其次,我们循环数据时,先循环出第一行记录,然后循环出该合并单元格的其他行记录,而我们的 html 是如下操作数据的:

<table ng-controller="repeatController" border="1">
    <thead>
        <td>年级</td>
        <td>姓名</td>
        <td>年龄</td>
    </thead>
    <tbody>
        <tr ng-repeat-start="group in list">
            <td rowspan="{{group.item.length}}">{{group.nian}}</td>
            <td>{{group.item[0].name}}</td>
            <td>{{group.item[0].age}}</td>
        </tr>
        <tr ng-repeat-end ng-repeat="single in group.item" ng-hide="$first">
            <td>{{single.name}}</td>
            <td>{{single.age}}</td>
        </tr>
    </tbody>
</table>
Clone this wiki locally