来自ng repeat

时间:2017-02-10 07:03:42

标签: html angularjs json angularjs-ng-repeat

我跟随Json:

{
    "FunctionIs": [{
        "id": 1,
        "name": "Test",
        "Type": "A"
    }, {
        "id": 2,
        "name": "Test2",
        "Type": "A"
    },{
        "id": 3,
        "name": "Test3",
        "Type": "A"
    },{
        "id": 4,
        "name": "Test4",
        "Type": "A"
    },{
        "id": 5,
        "name": "Test5",
        "Type": "B"
    },{
        "id": 6,
        "name": "Test6",
        "Type": "B"
    },{
        "id": 7,
        "name": "Test7",
        "Type": "C"
    },{
        "id": 8,
        "name": "Test8",
        "Type": "C"
    },]
}

我在html中通过ng-repeat填充这些值:

<tr ng-repeat="businessdata in userObj.businessJson">
    <td id="idIs">{{businessdata.id}}</td>
    <td>{{businessdata.name}}</td>
</tr>

每当“类型”发生变化时(从A到B,B到C,C到D再到等等),我想插入一个新的<tr>来显示标题(Type)第一次。任何人都可以帮助吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

您可以为不同的类型创建3个不同的ng-repeat

e.g。

<tr><th>A</th></tr>
        <tr ng-repeat="item in data | filter: {Type:'A'}">
          <td>{{item.name}}</td>
          <td>{{item.id}}</td>
        </tr>
        <tr><th>B</th></tr>
        <tr ng-repeat="item in data | filter: {Type:'B'}">
          <td>{{item.name}}</td>
          <td>{{item.id}}</td>
        </tr>
        <tr><th>C</th></tr>
        <tr ng-repeat="item in data | filter: {Type:'C'}">
          <td>{{item.name}}</td>
          <td>{{item.id}}</td>
        </tr>

这是一个有效的plunker