ember.js - Ember observer not getting most recent value -
i'm trying observe controller property in associated view, when so, old value. know async issues observers, per:
http://emberjs.com/guides/object-model/observers/
but using run.once() doesn't seem help. here's code:
mycontroller = ember.controller.extend({ testproperty: false, otherthingwatcher: function() { this.set('testproperty', true); console.log(this.get('testproperty')); // outputs true when someotherthing changes. }.observes('someotherthing'); }); myview = ember.view.extend({ checktestproperty: function() { console.log(this.get('controller.testproperty')); // ack! false! var = this; ember.run.once(this, function() { console.log(this.get('controller.testproperty')); // same thing. }); }.observes('controller.testproperty'); });
what have missed?
versions: debug: ember : 1.5.1 ember.js:3521 debug: ember data : 1.0.0-beta.8+canary.503c75c9 ember.js:3521 debug: handlebars : 1.3.0 ember.js:3521 debug: jquery : 1.9.1
there few problems code.
- you need use
extend
, notextend
- your observes can't end in
;
fixed code
myview = ember.view.extend({ checktestproperty: function() { console.log(this.get('controller.testproperty')); // ack! false! var = this; ember.run.once(this, function() { console.log(this.get('controller.testproperty')); // same thing. }); }.observes('controller.testproperty') });
Comments
Post a Comment