1

ember テキスト フィールド ビューを初期化して、クエリ文字列を事前入力しようとしています。しかし、ビューに init 関数を追加すると、他のすべての定義済みイベントのトリガーが停止します。

初期化の使用中にイベントを機能させ続けるにはどうすればよいですか?

App.SearchBarView = Ember.TextField.extend({
    throttle_instance: _.debounce(function(){
        var value = this.get('value');
        this.update();
    }, 1000),
    /**
    * Initialize the textbox with a set value
    */
    init: function(){
        var query = "testquery";
        if(query && query.length > 0){
            this.set('value', query[0]);
            this.get('controller').set('query', query[0]);
            this.update();
        }
    },
    insertNewline: function() {
        this.update();
    },
    /**
    * Handle the keyup event and throttle the amount of requests
    * (send after 1 second of not typing)
    */
    keyUp: function(evt) {
        this.get('controller').set('query', this.get('value'));
        this.throttle_instance();
    },
    /**
    * Update the pages results with the query
    */
    update: function(){
        var value = this.get('value');
        this.get('controller').filterByQuery(value);
    }

});
4

1 に答える 1

4

ビューのデフォルトの動作を維持するにはthis._super()、メソッド内で呼び出す必要があります。init

...
init: function() {
  this._super();
}
...

それが役に立てば幸い。

于 2013-08-13T09:25:11.200 に答える