如何以比 {{input escape-press='alertUser'}}
更 HTML 的格式编写“escape-press” Action .
我有一些像这样定义的输入 <input type="text" name="item-name" value={{item.name}} onblur={{action "confirmName" value="target.value"}} />
我想保留这个语法。
最佳答案
这与 onblur
的操作完全相同。在您的模板中,您将一个操作与 onkeypress
事件相关联,如下所示:
<input type="text" onkeypress={{action 'escape'}}>
然后,在 Controller 或组件中添加一个操作来处理它:
actions:{
escape(e){
if(e.key === 'Escape'){
//your code here
}
}
}
关于javascript - 如何像 Ember.js 模板一样将 "escape-press"声明到 HTML 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33356748/