dimanche 31 mai 2015

Use different components depending on a property of a model

In my Ember app I created one model with a color property

   App.Gecko = DS.Model.extend({
       color: fusia

    })

In the templates, I want to run different components depending on the color of the Gecko, so the desired logic in my templates is like this

 {{#each item in model}}
       {{if item.color == green}}
             code for a component
       {{/if}}
       {{if item.color == blue}}
            code for some other component
       {{/if}}
 {{/each}}

Except that Handlebars doesn't support the {{ if item.color == green }} logic. I understand that I'm supposed to use computed properties for this, but I can't figure out how to set it up so that different components would run depending on the color of the item. Question: How would I use a computed property on my controller (I'm assuming it belongs in the controller) to run different components depending on a property in the model?




Aucun commentaire:

Enregistrer un commentaire