Ember绑定属性没有更新,尽管控制器属性更新得很好

Ember bind-attr no updating, although controller property updates just fine

本文关键字:属性 更新 控制器 很好 Ember 绑定      更新时间:2023-09-26

我有一个控制器,当属性isProcessingSubmit设置为true时,它会禁用模板中的按钮。或者至少它应该禁用。

该模板具有以下代码:

<button type="submit" {{bind-attr disabled=isProcessingSubmit}}>Sign in</button>

在控制器上,我有这个:

App.SignInController = Ember.ObjectController.extend({
    isProcessingSubmit: false,
    enableProcessingSubmit: function() {
        this.set('isProcessingSubmit', true);
    },
    disableProcessingSubmit: function() {
        this.set('isProcessingSubmit', false);
    },
    init: function() {
        this._super();
        App.Events.on('ajax.onStart', this.get('enableProcessingSubmit'));
        App.Events.on('ajax.onComplete', this.get('disableProcessingSubmit'));
    },
    ...
});

这些事件由jQuery全局ajax事件的处理程序触发。我确认事件已正确激发,并且enableProcessingSubmitdisableProcessingSubmit已按预期调用。

此外,如果我在蝙蝠的控制器右侧将isProcessingSubmit标志设置为true,按钮将按预期禁用。所以基本上,当我调用set时,它看不到变化。

我错过了什么??

谢谢!

Nevermind,我忘了在事件回调中将控制器作为"this"传递:

App.Events.on('ajax.onStart', this, this.get('enableProcessingSubmit'));
App.Events.on('ajax.onComplete', this, this.get('disableProcessingSubmit'));

它现在起作用了。