Simple style click event updating style


#1
<ul class="small-block-grid-1 medium-block-grid-3 large-block-grid-4 carlist">
  {{#each carList itemController="car"}}
  <li>
    <label>
      <img {{ bind-attr src=filename title=name}} /> {{ view Ember.Checkbox checkedBinding="selected" }} {{ name }}
    </label>
  </li>
  {{/each}}
</ul>

In this example when the check box is selected id like to add a class to the label field whats the best ay of doing this? using a view? thanks!


#2

Sorted it out:

<ul class="small-block-grid-1 medium-block-grid-3 large-block-grid-4 carlist">
  {{#each carList itemController="car"}}
  <li>
    <label {{bindAttr class="selected:checked"}}>
      <img {{ bind-attr src=filename title=name}} /> {{ view Ember.Checkbox checkedBinding="selected" }} {{ name }}
    </label>
  </li>
  {{/each}}
</ul>

App.CarController = Em.ObjectController.extend({

selected: (function() { var car = this.get(“content”); var cars = this.get(“parentController.cars”); return cars.contains(car); }).property(),

selectedChanged: (function() {
var car = this.get(“content”); var cars = this.get(“parentController.cars”);

if (this.get("selected")) {
  emotions.pushObject(car);
} else {
  emotions.removeObject(car);
}

}).observes(“selected”)

});

Is there a nicer way of doing this? Had to find best practices for things in ember once it gets a tiny bit complex.

Thanks!