NgRepeat,按多个日期分组

时间:2015-03-02 04:59:32

标签: javascript angularjs angularjs-scope angularjs-ng-repeat angular-filters

我有以下系列:

[
 {
  "_id": "54efdd4a70726f7af1030000",
  "sequence_name": "Do Stuff",
  "calendar": [
   "2015-02-28T09:00:00.000Z",
   "2015-02-28T18:00:00.000Z",
   "2015-03-01T03:00:00.000Z"
  ]
 }
]

我需要像这样分组:

{
 "2015-02-28T09:00:00.000Z": [
  {
   "_id": "54efdd4a70726f7af1030000",
   "sequence_name": "Do Stuff",
  }
 ],
 "2015-02-28T18:00:00.000Z": [
  {
   "_id": "54efdd4a70726f7af1030000",
   "sequence_name": "Do Stuff"
  }
  ]
  // key/values keep going for each ...
}

这样我就可以(希望)显示如下数据:

<div ng-repeat='(date, scheds) in prettyDates'>
    <h6>{{ date | date: 'd MMM'  }}</h6>
    <div>{{ date | date: 'hh:mma' }}</div>
  <div ng-repeat='s in scheds'>
    <div class='event-time'>{{ s.start_time | date: 'h a' }}</div>
    <div class='event-title'>{{ s.sequence_name }}</div>
  </div>
</div>

当有多个要分组的项目或群组有重复的条目时,角度是否有办法进行分组?

1 个答案:

答案 0 :(得分:0)

我不认为angularJs会带有类似的东西。一个选项是使用lodash或类似的库在控制器中进行分组,然后循环遍历结果。

在lodash中查看此文档以获取groupBy: https://lodash.com/docs#groupBy