Reputation: 2105
I'm binding a model to my Controller and I'd like to observe any changes to its fields so I can reload some data and refresh a view.
Right now I have something really non-DRY like this:
goalController = Ember.Object.create({
...
recompute: function() { save model, load recomputed data from server }
...
nameChanged: function() { this.recompute() }.observes('content.name'),
incomeChanged: function() { this.recompute() }.observes('content.income')
});
Is there a Ember-y way of doing this?
Upvotes: 2
Views: 5151
Reputation: 2134
You can setup multiple observers at a time, so you could rewrite your example like so:
goalController = Ember.Object.create({
goalUpdated: function() {
// do your thing
}.observes("content.name", "content.income")
});
Here's a fiddle: http://jsfiddle.net/rlivsey/upZDU/
Upvotes: 7