Skip to content

Instantly share code, notes, and snippets.

@davelowensohn
Created February 18, 2016 18:30
Show Gist options
  • Select an option

  • Save davelowensohn/a566a3fa28f167423fe3 to your computer and use it in GitHub Desktop.

Select an option

Save davelowensohn/a566a3fa28f167423fe3 to your computer and use it in GitHub Desktop.
Ember 2.x nested @each workaround
// Nested eaches don't work, as per Ember rules:
// computedOrderSubTotal: computed('allOrderItems.@each.properties.@each.qty') [....]
// Workaround:
nestedProperties: computed.mapBy('allOrderItems', 'properties'),
computedOrderSubTotal: computed('nestedProperties.@each.qty', 'nestedProperties.@each.pricePerUnit', {
get() {
return this.get('nestedProperties').map( item => item.pricePerUnit * item.qty).reduce( (a,b) => a + b, 0);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment