【问题标题】:Ember bind-attr no updating, although controller property updates just fineEmber bind-attr 没有更新,虽然控制器属性更新就好了
【发布时间】:2014-12-23 08:22:04
【问题描述】:

当属性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 时它看不到变化。

我错过了什么??

谢谢!

【问题讨论】:

    标签: javascript jquery data-binding ember.js binding


    【解决方案1】:

    没关系,我忘了在事件回调中将控制器作为“this”传递:

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

    现在可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-19
      • 1970-01-01
      • 2018-03-28
      • 2014-03-01
      • 1970-01-01
      • 2021-04-23
      相关资源
      最近更新 更多