我正在尝试初始化我的 ember 文本字段视图以使用查询字符串预填充它。但是,每当我在视图中添加一个初始化函数时,所有其他定义的事件都会停止触发。
如何让我的事件在使用初始化时继续工作?
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);
}
});