Reputation: 1056
I made a JsBin where i demonstrate my problem:
Explonation:
In the first select i have customers. This select's value (customer_value) filters the 2nd select's (contactPersons) collection. If you select a customer, the "New Contact Person" button will be enabled. On click it adds a new Contact Person "Dale" to the Double R Diner. (In my app it is a form and the new contact person will be add to the selected customer)
The test
It would be nice to have the contact_persons property auto-updated when a new element is added. Shouldnt this be the default behaviour? Or i have to trigger it somehow?
Upvotes: 1
Views: 55
Reputation: 47367
Totally, a good rule of thumb, is to look at all of the properties that are required in your computed property, and if any of them make a difference in the value of the computed property (which I'd assume they all do), then they should be defined in the property method.
In this case, you will want to watch each property on a collection, for that we use the @each
keyword. It's important to note, you can't go more than one level deep with @each
. http://emberjs.com/guides/object-model/computed-properties-and-aggregate-data/
contact_persons: function(){
var id = parseInt(this.get('customer_value'),10);
return this.get('contactPersons').filterBy('partner.id',id);
}.property('customer_value', '[email protected]'),
What we're saying here is any time any new record is added/removed to contactPersons, or the partner
property changes on any of them (partner
itself, not partner.foo
, the partner
reference must change) then the property is dirty.
Example: http://jsbin.com/pexolude/72/edit
Upvotes: 1