[英]Action fired on multiple events
In CKEditor 4 I want to fire some action on key
and paste
events. 在CKEditor 4中,我想对key
和paste
事件进行一些操作。 I've got working code for single event: 我有单个事件的工作代码:
$('#some_id').ckeditor({
some: config
}).ckeditor().editor.on('key', function(evt) {
//some action here
});
And I don't want to repeat all code for next event. 而且我不想为下一个事件重复所有代码。 I've searched ckeditor docs - and it says that on
method takes only string, so give it an array of events isn't possible. 我已经搜索了ckeditor文档 -它说on
方法只接受字符串,因此不可能给它提供一系列事件。 I've tried pass multiple events as string key, paste
- it wasn't best idea. 我尝试过传递多个事件作为字符串key, paste
-这不是最好的主意。 Another way could be made an array of events and iterate it with code above - this solution seems to be not ideal, but the best I can figure out for now. 可以使事件数组成为另一种方法,并使用上面的代码对其进行迭代-这种解决方案似乎并不理想,但我目前能确定出最好的解决方案。 Have You any better ideas for this problem? 您对此问题有更好的主意吗?
Since nobody have any idea in this matter, I finished with best solution I could figure out on this moment: provide array of events and iterate it. 由于没有人对此事有任何想法,因此我在这一刻想出了最好的解决方案:提供一系列事件并对其进行迭代。 I paste here my solution for others facing same dillema: 我在这里将我的解决方案粘贴到其他面临相同难题的人身上:
var editor = $('#textarea').ckeditor({
//some:config
}).ckeditor().editor;
var events = ['event1', 'event2'];
for (event of events) {
editor.on(event, function(evt) {
//Yours actions
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.