0

I have the following collection:

[
 {
  "_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"
  ]
 }
]

I need to group it like this:

{
 "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 ...
}

So that I could (hopefully) display the data like this:

<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>

Does angular have a way of doing a groupBy when there are multiple items to group by or when groups will have duplicate entries?

Jenish Rabadiya
  • 6,708
  • 6
  • 33
  • 62
Rick
  • 8,366
  • 8
  • 47
  • 76
  • possible duplicate of http://stackoverflow.com/questions/14800862/how-can-i-group-data-with-an-angular-filter – Jenish Rabadiya Mar 02 '15 at 05:06
  • The user in that question is not grouping by a collection of dates. They are grouping by only one possible value. What I am trying to do is group by a collection of values, not a single attribute. That answer does not help me in my situation. – Rick Mar 02 '15 at 06:46

1 Answers1

0

I don't think that angularJs comes with anything like that. An option would be to use lodash or a similar library to do the grouping in your controller and then just loop over the results.

Check this documentation for groupBy in lodash: https://lodash.com/docs#groupBy

Eylen
  • 2,617
  • 4
  • 27
  • 42