An example collection (showing models only):
[
{
name: "Bob"
date: "Thu Mar 29 2012"
},
{
name: "James"
date: "Fri Mar 30 2012"
},
{
name: "Dylan"
date: "Fri Mar 30 2012"
},
{
name: "Stanley"
date: "Sat Mar 31 2012"
},
]
How can I use Underscore.js’ groupBy function to group models with the same date?
Use
_.groupBy(data, 'date');You could also use pass a custom function, but in this case it’s not necessary as the attribute shortcut syntax above works fine.
Demo: