Last active
May 16, 2016 20:47
-
-
Save trezy/af38ca48c66186470da3b005de3320eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Backbone from 'backbone' | |
import template from 'templates/BlogList.hbs' | |
export default class BlogList extends Backbone.Marionette.ItemView { | |
/******************************************************************************\ | |
Public Methods | |
\******************************************************************************/ | |
constructor (options) { | |
options = _.extend(options || {}, { | |
tagName: 'dl', | |
template: template | |
}) | |
super(options) | |
// We need to modify the collection's data structure. The current structure | |
// doesn't lend itself to the type of display we're going for | |
let groupedBlogs = this.collection.chain() | |
// Stick the models in arrays, grouped by month and year | |
.groupBy((model) => { | |
return model.get('date').format('MMMM YYYY') | |
}) | |
// The previous transforms sets the dates as keys in an object. We need to | |
// push the date into the object | |
.mapObject((value, key) => { | |
return { | |
blogs: value, | |
date: key | |
} | |
}) | |
// Convert the collection to an array, dumping the keys | |
.toArray() | |
// Return the final transformed object | |
.value() | |
// Set the collection to reflect the transformations | |
this.model = new Backbone.Model({groups: groupedBlogs}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment