mardi 29 septembre 2015

Ember action : target only 'this' of #each

I have a few actions that I'm placing on each item in a loop. Currently the action reveals all of the book-covers, instead of just one I want to target.

http://ift.tt/1VlSuPg

Looks like I can pass a parameter, but I'm not sure of the syntax.

I've done this before in earlier version and remember using this or should it be

{{action 'showCover' book}} ... ?


Controller

import Ember from 'ember';

export default Ember.Controller.extend( {

  actions: {
    showCover() {
      this.set('coverVisible', true);
    },
    ...
  }

});


Template

{{#each model as |book|}}

    <li class='book'>
        <article>
            {{#if coverVisible}}
            <figure class='image-w book-cover'>
                <img src='{{book.cover}}' alt='Cover for {{book.title}}'>
            </figure>
            {{/if}}

            ...

            {{#if book.cover}}
            {{#unless coverVisible}}
            <div {{action 'showCover'}} class='switch show-cover'>
                <span>Show cover</span>
            </div>
            {{/unless}}
            {{/if}}

{{/each}}




Aucun commentaire:

Enregistrer un commentaire