Skip to content

Instantly share code, notes, and snippets.

@bagby
Last active August 29, 2015 13:57
Show Gist options
  • Save bagby/9450322 to your computer and use it in GitHub Desktop.
Save bagby/9450322 to your computer and use it in GitHub Desktop.
{{each}} of computed property
models:
App.Lesson = DS.Model.extend({
contentCards: DS.hasMany('contentCard', { async: true }),
learningObjectives: function() {
return this.get('contentCards')
.mapBy('assignedLearningObjectives')
.flatten()
.mapBy('learningObjective')
.uniq()
.sortBy('sortOrder');
}.property().volatile() // yes it has come to this
});
App.ContentCard = DS.Model.extend({
lesson: DS.belongsTo('lesson'),
assignedLearningObjectives: DS.hasMany('assignedLearningObjective', { async: true })
});
App.AssignedLearningObjective = DS.Model.extend({
contentCard: DS.belongsTo('contentCard'),
learningObjective: DS.belongsTo('learningObjective')
});
App.LearningObjective = DS.Model.extend({
assignedLearningObjectives: DS.hasMany('assignedLearningObjective', { async: true })
});
template:
{{#each learningObjective in view.lesson.learningObjectives}}
{{learningObjective.title}}
{{/each}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment