Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay collection of elements, hide active element
    primarykey
    data
    text
    <p><strong>UPDATE</strong> Since asking this question I have redesigned my UI such that I no longer need this feature; however I'm leaving this open and active for the sake of helping others who end up with a similar problem.</p> <p>I'm listing a collection of elements inside a template and each element has a link that opens it up to the right of the list. When one is clicked, I want to hide just that element and show it again when another one is clicked. My current approach to doing this is to set an attribute (active) to true on the model. This feels wrong for three reasons:</p> <ol> <li>This attribute is not actually part of the model's schema, it's just arbitrary; which makes it seem like a controller concern (see below for why that doesn't work)</li> <li>I have to first set active to false on all models, forcing me to change another router's model, which may be good or bad, I'm not sure</li> <li>In the recent PeepCode screencast he showed using <code>@each.{attribute}</code> to bind to an attributes in an array; this makes me feel like there must be something similar I could do (like <code>this.set("@each.active", false)</code>) to set them all in one fell swoop</li> </ol> <p>I wanted to use a method on the controller but it doesn't seem I can pass arguments into functions in Handlebars if statements.</p> <p>Here's the code I'm using to render the list:</p> <pre><code> {{#each note in controller}} {{!v-- I was trying to do {{#if isCurrentNote note}} but that seems to be invalid handlebars}} {{#unless note.active}} &lt;li class="sticky-list-item"&gt; {{view Ember.TextArea classNames="sticky-note" valueBinding="note.content"}} {{#linkTo note note classNames="sticky-permalink"}} ∞ {{/linkTo}} &lt;/li&gt; {{/unless}} {{/each}} </code></pre> <p>And here are the routes:</p> <pre><code>App.NotesController = Ember.ArrayController.extend({ // v-- this is what I was trying to do, but couldn't pass note in the template isCurrentNote: function(note){ return this.get("currentNote") == note; }.property("currentNote") }); App.NoteRoute = Ember.Route.extend({ setupController: function(controller,model){ this.modelFor("notes").forEach(function(note){ note.set("active", false); }); model.set("active", true); } }); </code></pre> <p>Like I said, what I have works, but it feels wrong. Can anyone confirm my suspicion or help ease my soul a bit?</p> <p>Thanks!</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.
    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