2

私は次のコントローラーを持っています:

var ProductsController = Ember.ArrayController.extend({
  search: function(queryString) {
    this.set('model', App.Product.find({query: queryString }));
  }
});

およびテキスト フィールド:

var SearchFieldView = Ember.TextField.extend({
  insertNewline: function() {
    this.get('controller').search(this.get('value'));
  }
});

ここで、コントローラーが検索機能で新しいモデルをロードするときに、テキスト フィールドを無効にしたいと考えています。ビューのようなものを使用してdisabledBinding: 'controller.content.isLoaded'も機能しません。

4

2 に答える 2

1
var ProductsController = Ember.ArrayController.extend({
  search: function(queryString) {
    this.set('isLoadingData', true);

    var products = App.Product.find({query: queryString });
    this.set('model', products);

    products.then(function() {
      this.set('isLoadingData', false);
    });
  }
});


var SearchFieldView = Ember.TextField.extend({
  attributeBindings: ['disabled'],
  disabledBinding: 'controller.isLoadingData',
  insertNewline: function() {
    this.get('controller').search(this.get('value'));
  }
});

説明:

に設定された要求を実行する前isLoadingDatatrue。ember-datafind()Promise APIを使用します:リクエストが正常に完了したときに を設定isLoadingDataします。失敗したケースを処理したい場合があります。参照については、 RSVP.jsを参照してください。最後に の無効なプロパティをにバインドします。falseEmber.TextFieldcontroller.isLoadingData

于 2013-07-24T12:37:25.530 に答える