Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Observer functionality in Ember?

I can't get an observer to actually do anything in Ember.js. Basically, I have a Ember.Select dropdown menu, and want to bind some more action to the event of selecting the value in the dropdown. For example:

App.selectedPersonController = Ember.Object.create({
  person: null,
  personDidChange: function() {
    // do something here when the person changes
    console.log("PERSON CHANGED")
  }.observes('person')
});

And nothing is happening, even though the 'person' attribute is getting updated. Any suggestions?

like image 557
reptilicus Avatar asked May 16 '26 21:05

reptilicus


2 Answers

This is due to the fact that as of version pre4 you cannot set a property or observable upon the Em.*.create() function. You have to first use the .extend() function first and set all your properties and observables in that, then create that object.

As an example, take a look at this jsfiddle that is working with the extend functionality. Then try to take it away by using only create and you'll see that the app no longer works.

like image 124
DF_ Avatar answered May 19 '26 10:05

DF_


Or use createWithMixins() instead of create()

like image 39
tevch Avatar answered May 19 '26 09:05

tevch