按布尔值对ng-repeat分组进行排序

时间:2013-12-03 11:42:22

标签: angularjs angularjs-ng-repeat

在我的角度js尝试中,我有一个json:

[
  {
    "id": "1111",
    "peopleRelated": [
      {
        "summary": "Manager",
        "personName": "Suzanne",
        "personId": 382043,
        "rated" : true
      },
      {
        "summary": "VP",
        "personName": "Dave",
        "personId": 34532
        "rated" : false
      }

    ],
    "title": "Title1",    
  },
  {
    "id": "2222",
    "peopleRelated": [
      {
        "summary": "Manager",
        "personName": "Kevin",
        "personId": 38864
        "rated" : true
      }     
    ],
    "title": "Title2",    
  }
]

html如下:

<div ng-repeat="mydata in data>
  <div ng-repeat="personData in mydata.peopleRelated">
  {{personData.personName}}
  <div>
</div>

我希望首先对personName进行排序,例如“rated = false”名称 我应该怎么做呢? 感谢

1 个答案:

答案 0 :(得分:5)

不太确定这是否是你所要求的,但是

<div ng-repeat="personData in mydata.peopleRelated | orderBy:'rated'">
  {{personData.personName}} {{personData.rated}}
<div>

对内循环进行排序