我试图在其关联视图中观察控制器属性,但是当我这样做时,我总是得到旧值。我知道观察者的异步问题,如下:
http://emberjs.com/guides/object-model/observers/
但使用run.once()似乎没有帮助。这是我的代码:
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! This is false!
var that = this;
Ember.run.once(this, function() {
console.log(this.get('controller.testProperty')); // Same thing.
});
}.observes('controller.testProperty');
});
我错过了什么?
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
答案 0 :(得分:1)
您的代码存在一些问题。
extend
,而不是Extend
;
MyView = Ember.View.extend({
checkTestProperty: function() {
console.log(this.get('controller.testProperty')); // Ack! This is false!
var that = this;
Ember.run.once(this, function() {
console.log(this.get('controller.testProperty')); // Same thing.
});
}.observes('controller.testProperty')
});