javascript - 使用 init 时 Ember 文本字段事件不起作用

标签 javascript ember.js

我正在尝试初始化我的 ember 文本字段 View 以使用查询字符串预填充它。但是每当我向我的 View 添加一个初始化函数时,所有其他定义的事件都会停止触发。

如何让我的事件在使用初始化时继续工作?

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._super() 来维持 View 的默认行为:

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

希望对您有所帮助。

关于javascript - 使用 init 时 Ember 文本字段事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18204363/

相关文章:

php - 如何根据添加到 URL 中的数据在页面上加载数据 #a=1380369&i=23007472

javascript - Ember.js Application.inject 循环依赖

javascript - 在 Emberjs/handlebars 中为 html 元素定义 ID 失败

Javascript:使用递归迭代对象来构建导航列表

javascript - Angular Material : nested expansion panels spill-over when closed

javascript - jQuery .append 不适用于 .submit

javascript - ReactJS 商店未注册

jquery - EmberJS 应用程序...可以与 UI 框架集成吗?

ember.js - Ember 1.0.0 RESTAdapter 失败

javascript - 在 Emberjs 中设置从路由到 Controller 的数据错误