Skip to content

Commit

Permalink
{} syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreybiles committed Jul 22, 2015
1 parent ad58784 commit 153df34
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 14 additions & 5 deletions ember_admin/app/demonstrations/computed-getter/controller.js
Expand Up @@ -14,11 +14,11 @@ export default Ember.Controller.extend({
}),

documentaries: [
{name: 'Iron Man 1', release: '2008', budget: 140000000},
{name: 'Iron Man 2', release: '2010', budget: 200000000},
{name: 'The Avengers', release: '2012', budget: 220000000},
{name: 'Iron Man 3', release: '2013', budget: 200000000},
{name: 'Avengers 2', release: '2015', budget: 250000000}
{name: 'Iron Man 1', release: '2008', budget: 140000000, boxOffice: 318000000},
{name: 'Iron Man 2', release: '2010', budget: 200000000, boxOffice: 312000000},
{name: 'The Avengers', release: '2012', budget: 220000000, boxOffice: 623000000},
{name: 'Iron Man 3', release: '2013', budget: 200000000, boxOffice: 408000000},
{name: 'Avengers 2', release: '2015', budget: 250000000, boxOffice: 455000000}
],

totalDocumentaryBudget: Ember.computed('documentaries.@each.budget', function(){
Expand All @@ -27,5 +27,14 @@ export default Ember.Controller.extend({
totalBudget += Number(documentary.budget);
})
return totalBudget
}),

totalDocumentaryProfit: Ember.computed('documentaries.@each.{budget,boxOffice}', function(){
var totalProfit = 0;
this.get('documentaries').forEach(function(documentary){
totalProfit += Number(documentary.boxOffice);
totalProfit -= Number(documentary.budget);
})
return totalProfit
})
});
5 changes: 3 additions & 2 deletions ember_admin/app/demonstrations/computed-getter/template.hbs
Expand Up @@ -6,7 +6,8 @@ Business Card: {{businessCard}}

<h1>Relevant Documentaries</h1>
{{#each documentaries as |documentary|}}
{{input value=documentary.name}}, released in {{input value=documentary.release}} for {{input value=documentary.budget}} million dollars<br>
{{input value=documentary.name}}, released in {{input value=documentary.release}} for ${{input value=documentary.budget}}, bringing in ${{input value=documentary.boxOffice}}.<br>
{{/each}}

Total budget: {{totalDocumentaryBudget}}
Total budget: {{totalDocumentaryBudget}}<br>
Total profit: {{totalDocumentaryProfit}}

0 comments on commit 153df34

Please sign in to comment.