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?
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/
alarm
property inside the model, and an observer hat toggles the alarm, inside the model, over all the properties that I wanted to observe from the controller. Finally a single observe over model.alarm
. Still ugly, but the controller doesn't need to now the internals of the model under this scenario - robertodecurnex 2015-05-15 17:35
``` goalController = Ember.Object.create({
}); `` - srt32 2015-04-02 18:40