Ryan Her
Ryan Her

Reputation: 1117

EmberJS - How to display subset of a model in a view

I am very new (started today) to Ember and cannot figure how how to set this up in a correct manner.

Models:

Post, Comment

On the 'show' template for Post, I want to display only the comments that are not blocked (isBlocked is a attribute of Comment model). Should I use a View and pass in a param to filter out the comments?

I cannot find an useful example or tutorial that explains this. Is there a way similar to how this would be done in Rails with partials and locals or something?

Upvotes: 1

Views: 196

Answers (1)

Darshan Sawardekar
Darshan Sawardekar

Reputation: 5075

You can use a computed property that uses filterProperty to filter your model inside your controller. Then use that computed property to display in your template.

Assuming your Comment model has an isBlocked attribute, you can set up a computed property like,

comments: function() {
  return this.filterProperty('isBlocked', false);
}.property('@each.isBlocked')

Then in the template use comments as the collection to iterate over. The comments collection will have all comments except those where isBlocked is true.

Upvotes: 1

Related Questions