Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access the parent controller that is not singleton when using {{render}}?
    text
    copied!<p>I wanna access the <code>parent</code> controller, from a controller visited by <code>{{render}}</code>. I've tried <code>needs</code> but its not working. Its giving me a singleton Controller, but I want the explicit <code>controller</code> with its <code>content</code>.</p> <p>How can I solve this Problem to render a matrix?</p> <p>I've created a <a href="http://emberjs.jsbin.com/ArUjeVi/5/edit" rel="nofollow">little demonstration (JS Bin)</a>, its the same code as below.</p> <p>JS:</p> <pre><code>App = Ember.Application.create(); App.Router.map(function() { // put your routes here }); App.IndexRoute = Ember.Route.extend({ model: function() { return { items: [ App.Item.create({ id: 'i1' }), App.Item.create({ id: 'i2' }) ], places: [ App.Place.create({ id: 'p1' }), App.Place.create({ id: 'p2' }) ] }; } }); App.Place = Em.Object.extend({ stores: function() { if (this.get('id') == 'p1') { return [App.Store.create({ id: 's1', itemId: 'i1', quantity: 4 }), App.Store.create({ id: 's2', itemId: 'i2', quantity: 6 }), App.Store.create({ id: 's3', itemId: 'i2', quantity: 12, comment: 'broken' })]; }else { return [App.Store.create({ id: 's4', itemId: 'i2', quantity: 12 })]; } }.property('id') }); App.Item = Em.Object.extend({ }); App.Store = Em.Object.extend(); App.PlaceController = Em.ObjectController.extend({ needs: ['index'] }); App.ItemOnPlaceController = Em.Controller.extend({ needs: 'place', stores: function() { var self = this; // Problem: controllers.place.content == null! alert(this.get('controllers.place.content')); //return this.get('controllers.place.content.stores').find(function(store) { // return self.get('content.id') == store.get('itemId'); //}); }.property('controllers.place.content.stores', 'content.id') }); </code></pre> <p>And the handlebars templates:</p> <pre><code>&lt;script type="text/x-handlebars"&gt; &lt;h2&gt;Welcome to Ember.js&lt;/h2&gt; {{outlet}} &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="index"&gt; &lt;h1&gt;Demo&lt;/h1&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;&lt;/th&gt; {{#each item in items}} &lt;th&gt;Item {{item.id}}&lt;/th&gt; {{/each}} &lt;/tr &lt;/thead&gt; &lt;tbody&gt; {{#each place in places}} {{render "place" place}} {{/each}} &lt;/tbody&gt; &lt;/table&gt; &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="place"&gt; &lt;tr&gt; &lt;th&gt;Place {{id}}&lt;/th&gt; {{#each item in controllers.index.content.items}} &lt;td&gt; {{render itemOnPlace item}} &lt;/td&gt; {{/each}} &lt;/tr&gt; &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="itemOnPlace"&gt; {{content.id}} &lt;ul&gt; {{#each stores}} &lt;li&gt;{{quantity}} - {{comment}}&lt;/li&gt; {{/each}} &lt;/ul&gt; &lt;/script&gt; </code></pre>
 

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