在Angularjs中的多个字段上自定义排序

时间:2015-05-11 18:45:56

标签: javascript angularjs sorting angularjs-directive

我需要根据两个字段对ng-repeat列表进行排序:

1>状态:红色,橙色,绿色。

2 - ;日期:(年龄到现在的日期)

排序应该是所有红色,而不是所有橙色和最后全部绿色

下面是我的JSON:

{
    "data": [
      {"name": "John", "startDate": "14,Feb,2015", "status": "orange"},
      {"name": "John1", "startDate": "18,Feb,2015", "status": "red"},
      {"name": "John2", "startDate": "28,Feb,2015", "status": "red"},
      {"name": "John3", "startDate": "14,Feb,2015", "status": "red"},
      {"name": "John4", "startDate": "19,Feb,2015", "status": "orange"},
      {"name": "John5", "startDate": "15,Feb,2015", "status": "green"},
      {"name": "John6", "startDate": "21,Feb,2015", "status": "red"}
  ]
}

我希望上面的JSON排序如下:

{
    "data": [
      {"name": "John3", "startDate": "14,Feb,2015", "status": "red"},
      {"name": "John1", "startDate": "18,Feb,2015", "status": "red"},
      {"name": "John6", "startDate": "21,Feb,2015", "status": "red"},
      {"name": "John2", "startDate": "28,Feb,2015", "status": "red"},
      {"name": "John5", "startDate": "15,Feb,2015", "status": "green"},
      {"name": "John", "startDate": "14,Feb,2015", "status": "orange"},
      {"name": "John4", "startDate": "19,Feb,2015", "status": "orange"}
  ]
}

0 个答案:

没有答案