Javascript 使用init时余烬文本字段事件不起作用

Javascript 使用init时余烬文本字段事件不起作用,javascript,ember.js,Javascript,Ember.js,我正在尝试初始化我的余烬文本字段视图,以使用查询字符串对其进行预填充。但每当我向视图中添加init函数时,所有其他定义的事件都会停止触发 如何使事件在使用初始化时保持工作状态 App.SearchBarView = Ember.TextField.extend({ throttle_instance: _.debounce(function(){ var value = this.get('value'); this.update(); }, 10

我正在尝试初始化我的余烬文本字段视图,以使用查询字符串对其进行预填充。但每当我向视图中添加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);
    }

});

您需要在
init
方法中调用
this.\u super()
,以维护视图的默认行为:

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

希望有帮助。

您需要在
init
方法中调用
this.\u super()
,以维护视图的默认行为:

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

希望有帮助。

正是我想要的。谢谢!正是我想要的。谢谢!