如何在 emberjs 中的 textarea 上收听粘贴事件 [英] How to listen to a paste event on a textarea in emberjs
本文介绍了如何在 emberjs 中的 textarea 上收听粘贴事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含以下模板的组件:
{{textarea value=content autofocus="autofocus"}}<button {{action 'cancel'}}>cancel</button>
如何在我的组件中收听此文本区域上的 paste
事件?
我尝试创建粘贴操作,但这似乎不起作用:
App.EditableTextComponent = Ember.Component.extend({模板名称:'组件/可编辑文本',动作:{粘贴:函数(){控制台日志(参数);}}});
解决方案
正如@wojciech-bednarski 在他的评论中所建议的那样,我已将自定义事件侦听器添加到我的应用程序中:
var App = Ember.Application.create({自定义事件:{粘贴:粘贴"}});
然后可以在我的组件中收听它
App.EditableTextComponent = Ember.Component.extend({粘贴:函数(事件){控制台日志(事件)}});
I have a component that holds the following template:
<div>
{{textarea value=content autofocus="autofocus"}}
<button {{action 'cancel'}}>cancel</button>
</div>
How can I listen to a paste
event on this textarea in my component?
I tried to create a paste action but this doesn't seem to work:
App.EditableTextComponent = Ember.Component.extend({
templateName: 'components/editable-text',
actions: {
paste: function() {
console.log(arguments);
}
}
});
解决方案
As @wojciech-bednarski suggest in his comment, I have added the custom event listener to my app:
var App = Ember.Application.create({
customEvents: {
paste: "paste"
}
});
and could then listen to it in my component
App.EditableTextComponent = Ember.Component.extend({
paste: function(event) {
console.log(event)
}
});
这篇关于如何在 emberjs 中的 textarea 上收听粘贴事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文