进入灰烬的行动

时间:2013-09-07 06:46:44

标签: ember.js action

无论如何都有这个文字输入

<input type="text" aria-controls="existing-user-table" placeholder="Search">

在用户点击进入时触发控制器上的操作?

我不喜欢将其封装在表单标签中或创建一个按钮,只是输入文本字段。

3 个答案:

答案 0 :(得分:29)

使用{{input}}助手 - 如果您包含一个动作参数,它将在用户点击进入时在控制器上触发该动作。所以:

{{input action="myAction" aria-controls="existing-user-table" placeholder="Search"}}

input helper api docs没有提及此功能,但帮助程序只是包裹Ember.TextField

也可以通过指定onEvent property来触发对keyPress的操作而不是输入:

{{input action="myAction" onEvent="keypress" aria-controls="existing-user-table" placeholder="Search"}}

答案 1 :(得分:28)

输入助手有一个insert-newline动作,当用户按下回车键时会触发该动作。

{{input type='text' aria-controls='existing-user-table' placeholder='Search' insert-newline='myAction'}}

Text Input Helpers

Insert Newline docs

答案 2 :(得分:17)

从Ember v1.13.0开始,对输入助手的操作进行了描述我们应该使用enterkey-press代替action

参考Ember Docs

{{input value=someValue enter='someAction'}}

当用户在文本输入上按Enter键时,这将触发上述操作