Filtering hasMany relationship data and using itemController in templates


I’ve had issues in the past on how to correctly approach filtering data in hasMany relationships. I’ve used Ember.RSVP.hash to return a filtered set of items, but this creates an issue with itemController - I can not use it for that filtered hash of items. I have a property on the itemController that is calculated for each item, and as the result of this type of filtering is a hash of items, it does not work.

For example, I have a “Product” model that hasMany “Shop”. I want to display this information and filter the Shops and Products based on userinput in Ember.TextField. Filtering both “Shop” and “Product” in the view.

1 Product information

  • shop
  • shop

2 Product information

  • shop
  • shop

I am trying to figure out how to best approach this type of situation in a more Ember-way. Here’s what I’ve done now:

I’m interested in how this should be done in Ember, and if anyone has any examples to give.

Here’s and Ember.js JSBin illustrating my problem. Check with Ember inspector before & after filtering, how the itemController finalPrice property changes from a value to NaN with filtered data:


Any pointers? I’m still stuck with this issue :smile: