I have a list of products that I'd like to add to an array on another controller for messages. I have created an objectcontroller for the product model so that I can toggle a "selected" attribute (which is working fine) but my observer in the message controller isn't firing. Heres the objectcontroller for the product:
App.ProductController = Ember.ObjectController.extend({
selected: false,
actions:{
toggleSelected: function(){
this.set('selected', !this.get('selected'));
}
}
});
Here's the message controller -- the products are just for a test, but do I (/can I) declare an itemcontroller for a list like this?
App.MessagesNewController = Ember.Controller.extend({
needs: ['product'],
products: [{name: 'product 1', id: 1}, {name: 'product 2', id: 2}],
selectedProducts: function(){
var products = this.get('products');
return products.filterBy('selected', true);
}.observes('[email protected]')
});
and the template:
{{#each product in products itemController="product"}}
<div {{bind-attr class=":well product.selected"}} {{action 'toggleSelected'}}>
{{product.name}}
</div>
{{/each}}
I'm very new to Ember so I appreciate any direction or best-practices for this type of thing. Thanks
Note: I'm using ember-data also, if that makes any difference.