Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well I'll have to answer my own question on this one. As @peter-wagenet and @bradley-priest suggested, I did need to make use of the ability to send a context using the action helper.</p> <p>This used in conjunction with <code>{{#each item in list}}</code> I can set the context to the specific object being viewed.</p> <p>I also had to create Ember.Object(s) for the availableIn array of objects so that I could use the .set method.</p> <p>So without further ado, here's my working solution. If you have a better solution, I'd be more then happy to see it.</p> <p>Template</p> <pre><code>&lt;script type="text/x-handlebars" id="application"&gt; &lt;h1&gt;If you're gonna survive out here, you've got to know where your towel is.&lt;/h1&gt; {{outlet}} &lt;/script&gt; &lt;script type="text/x-handlebars" id="towel"&gt; &lt;h2&gt;The availableIn:&lt;/h2&gt; {{outlet}} &lt;/script&gt; &lt;script type="text/x-handlebars" id="towels"&gt; {{#each item in availableIn}} &lt;div&gt; {{! The default click action will find the controller and look for doStuff and send it the event with the context set to item }} &lt;a {{action doStuff item target="controller"}}&gt;{{item.color}}&lt;/a&gt; &lt;/div&gt; {{/each}} &lt;/script&gt; </code></pre> <p>Javascript</p> <pre><code>window.App = Ember.Application.create({ ready: function() { this.initialize(); } }); window.App.Router = Ember.Router.extend({ root: Ember.Route.extend({ index: Ember.Route.extend({ route: '/', connectOutlets: function(router) { var controller = router.get('applicationController'); controller.connectOutlet('towel'); controller = router.get('towelController'); controller.connectOutlet('towels'); } }) }) }); window.App.ApplicationView = Ember.View.extend({ templateName: 'application' }); window.App.ApplicationController = Ember.Controller.extend(); window.App.TowelController = Ember.ObjectController.extend(); window.App.TowelView = Ember.View.extend({ templateName: 'towel' }); // Towel Object model window.App.Towel = Ember.Object.extend({ name: null, availableIn: [], wetness: 0, isEditing: false }); // Style Object model window.App.Style = Ember.Object.extend({ color: null, size: null }); // Create some style instances var style1 = window.App.Style.create({ color: "red", size: "small" }); var style2 = window.App.Style.create({ color: "blue", size: "medium" }); // Create a towel instance var drt = window.App.Towel.create({ name: "Dry Towel", availableIn: [style1, style2], wetness: 0, isEditing: true }); // The Towels Controller window.App.TowelsController = Ember.ObjectController.extend({ // Set the content to our dummy data content: drt, // Define the action doStuff doStuff: function(event) { // Grab the context which is the object being cliked and change it's color property to 'purple' event.context.set('color', 'purple'); } }); // The Towels View window.App.TowelsView = Ember.View.extend({ templateName: 'towels' });​ </code></pre> <p>Working fiddle: <a href="http://jsfiddle.net/EasyCo/cE2xP/" rel="nofollow">http://jsfiddle.net/EasyCo/cE2xP/</a></p>
    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