0

在 Ember 2 中,我正在尝试做可能是最简单的事情。当我将事件绑定到输入元素时,我希望将事件参数传递给我的动作处理程序,但我无法得到它。只需检查keyCode 13,它是键盘上的“输入”键。

 {{input type=text
           value=model.filters.query
           placeholder="Search by title"
           action="search" onEvent="key-press"
 }}

我的函数处理程序是:

search(newValue){
 // I am only getting newValue and not the event object
}
4

1 回答 1

2

默认情况下不公开 DOM 事件。这是一个关于那个的问题

但是对于您的用例,我们可以通过在输入助手的“输入”属性中指定操作来在按下输入按钮时触发操作。您可以参考this,其中列出了可以添加操作的不同用户事件。

{{input 
  type=text
  value=query
  placeholder="Search by title"
  enter="search"
}}

App.IndexController = Em.Controller.extend({
  query: '',
  actions: {
    search: function(value) {
      alert(value);
    } 
  }
});

这是一个工作演示。

于 2016-02-25T07:46:49.350 回答