Ember.js 余烬观察者未获取最新值
我试图在关联视图中观察控制器属性,但当我这样做时,总是得到旧值。我了解观察员的异步问题,具体如下: 但是使用run.once()似乎没有帮助。这是我的密码:Ember.js 余烬观察者未获取最新值,ember.js,Ember.js,我试图在关联视图中观察控制器属性,但当我这样做时,总是得到旧值。我了解观察员的异步问题,具体如下: 但是使用run.once()似乎没有帮助。这是我的密码: MyController = Ember.Controller.extend({ testProperty: false, otherThingWatcher: function() { this.set('testProperty', true); console.log(this.get('testPro
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
您的代码有一些问题
extend
,而不是extend
结尾代码>
上面的代码不是有效的javascript,这意味着它甚至无法访问这些日志,这可能意味着您没有显示实际不起作用的代码。抱歉。我凭记忆打出来的!我的代码是正确的(只是从内存中键入的代码很糟糕,对不起!),但是通过查看您的JSBin,我找到了真正的答案。实际问题:我的视图被呈现,然后,在排序之后,重新呈现-这破坏了正在讨论的属性。将所述变量移动到父(列表)控制器修复了该问题。非常感谢。
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')
});