2
votes

I have a backbone collection of models with each model containing a date. (this represents calendar entries and the collection is a weeks worth) I need to split the collection into multiple collections grouped by date. (eg: group each calendar entry by day but have the whole week available as a collection)

Collection: [M:{dateA, ...},
             M:{dateA, ...},
             M:{dateB, ...},
             M:{dateC, ...}]

Split into:

[
 {Collection1: [M:{dateA, ...},
                M:{dateA, ...}]
 },
 {Collection2: [M:{dateB, ...}]
 },
 {Collection3: [M:{dateC, ...}]
 }
]

I have come to the solution in a round about way using underscore and finding all the unique dates and using those to filter into the array of collections but I was wondering if there was a simpler way. To filter them?

1

1 Answers

0
votes

This question seems have already been answered here:

How to use groupBy in Backbone.js to group collections?

Hope that helps.