vendredi 5 mai 2017

Apply property to all but but last component in template

I'm pretty new to Ember.js so I'm wondering if anyone might know of a "clever" way to accomplish this.

I have several instances of a component I am rendering in a template representing steps in a process. I'd like to set a boolean property (collapse) on all of them except for the last one. I could do this by hand using computed properties (see example below), but this would be onerous because each step in the process would have different (sometimes multiple) conditions for this boolean property to be set, and would become harder to maintain the larger this part of my code base gets.

This is what that would look like:

<ul>
  <li></li>
  ...
  <li></li>
  ...
  <li></li>
</ul>

I was hoping there might be a way to select (or track) all instances of a component in a template and apply the property to them in one step - or maybe add them to an Array as I put them in the template and then iterate over that later, but I haven't been able to successfully do this yet.

Can anyone suggest if this is viable? Thank you!




Aucun commentaire:

Enregistrer un commentaire