Note that there are some explanatory texts on larger screens.

plurals
  1. POSelected item in a template, is there any solution for a context aware bindAttr?
    primarykey
    data
    text
    <p>The problem is as follows: In our application we have several buttons, navigation icons etc., which we want to be 'selected' when they have been clicked. We can have multiple elements marked at the same time.</p> <p>The secondary reason for me wanting to do this is that when I read the new Guides on emberjs.com I get the feeling that templates should be used more than stated before and that templates should have the responsibility of rendering the DOM, while the views should be used to handle sophisticated events (if any) or to create common/shared components to be reused in the application.</p> <p>Currently the view is handling this:</p> <pre><code>app.NavView = Ember.CollectionView.extend({ ... itemViewClass: Ember.View.extend({ ... classNameBindings: ['isSelected:selected'] isSelected: function () { return this.get('controller.selected') === this.get('content'); }.property('controller.selected') }) }); </code></pre> <p>But that is all the View basically is doing, I would like to drop the entire View and just use a template for this</p> <p>I have tried with a template approach, and dropped the entire View concept.</p> <pre><code>&lt;div id="main-menu"&gt; {{#each content}} &lt;div {{bindAttr class="controller.isSelected:selected"}}&gt; {{{iconsvg}}} {{name}} &lt;/div&gt; {{/each}} &lt;/div&gt; </code></pre> <p>But my problem here of course is that bindAttr doesn't know about the context it’s in, and cannot 'send' this to the isSelected property on the controller to evaluate if it is this element that is selected or not.</p> <p>Is there a good solution to do this without a view, or am I forced to use a view? Or am I thinking the design part and responsibility of Templates/views/controllers wrong? </p> <p>Any response is appreciated!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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