Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber.js: how to use an ArrayController to describe multiple models?
    primarykey
    data
    text
    <p>I am trying to set up a dashboard that can monitor and display information on multiple models. The ArrayController seems like the correct object to use, but I am not sure what I am doing wrong. </p> <p>Can someone explain where I've gone astray here?</p> <p><strong>jsBin Example:</strong> <a href="http://jsbin.com/IgoJiWi/8/edit?html,js,output" rel="nofollow">http://jsbin.com/IgoJiWi/8/edit?html,js,output</a></p> <p><strong>javascript:</strong></p> <pre><code>App = Ember.Application.create(); /* ROUTES */ App.Router.map(function() { this.resource('options'); this.resource('dashboard'); }); App.IndexRoute = Ember.Route.extend({ redirect: function() { this.transitionTo('options'); } }); App.OptionsRoute = Ember.Route.extend({ model: function() { var a = Em.A(); a.pushObject( App.Options.create({title: 'A', cost: '100'})); a.pushObject( App.Options.create({title: 'B', cost: '200'})); a.pushObject( App.Options.create({title: 'C', cost: '300'})); return a; } }); /* MODELS */ App.Options = Ember.Object.extend({ title: '', cost: '', quantity: '' }); /* CONTROLLERS */ App.optionsController = Ember.ArrayController.extend({ legend: 'test', len: this.length, totalCost: function() { return this.reduce( function(prevCost, cost, i, enumerable){ return prevCost + cost; }); }.property('@each.cost') }); </code></pre> <p><strong>handlebars:</strong></p> <pre><code> &lt;script type="text/x-handlebars" data-template-name="application"&gt; &lt;p&gt;&lt;strong&gt;Ember.js example&lt;/strong&gt;&lt;br&gt;Using an ArrayController to access aggrigated data for all models of type X.&lt;/p&gt; {{render dashboard}} {{outlet}} &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="options"&gt; &lt;h2&gt;Options:&lt;/h2&gt; &lt;dl&gt; {{#each}} &lt;dt&gt;Title: {{title}}&lt;/dt&gt; &lt;dd&gt;Cost: {{cost}} {{input value=cost}}&lt;/dd&gt; {{/each}} &lt;/dl&gt; &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="dashboard"&gt; &lt;h2&gt;Overview:&lt;/h2&gt; &lt;p&gt;Why won't this display info about the options below? I suspect that the optionsController does not actually contain options A-C...&lt;/p&gt; {{#with App.optionsController}} &lt;p&gt;Total number of options (expect 3): {{len}}&lt;/p&gt; &lt;p&gt;Total cost of options (expect 600): {{totalCost}}&lt;/p&gt; {{/with}} &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload