简体   繁体   English

CKEDITOR:在SetData之后附加“ keydown”事件吗?

[英]CKEDITOR : Attache “keydown” event after SetData?

I'm trying to do something in CKEditor.I made some Plugin's which has event listener 我正在尝试在CKEditor中做一些事情,我做了一些具有event listener插件

options.Ok, It's Working fine when I'm Starting the Editor. 选项。好的,当我启动编辑器时,它工作正常。

But In my situation, I open some other Files in the mean time.So whenever user click the file i get the data and set Content to CKEditor using below code. 但是在我的情况下,我同时打开了其他文件,因此每当用户单击该文件时,我都会获取数据并将Content设置为CKEditor,使用下面的代码。

editor.setData('MY HTML FILE CONTENT');

It's working fine.But after I try to trigger the 'event listener' then it fails. 它工作正常,但是在我尝试触发``事件监听器''之后,它失败了。

What Should I do now ? 我现在应该怎么办 ?

Provided that you are doing this inside init method, please add the listener to the editor and not to the document. 假设您正在init方法中进行此操作,请将侦听器添加到编辑器而不是文档中。 That way it will not get removed when document is removed: 这样,在删除文档时将不会删除它:

editor.on( 'instanceReady', function( e ) {
    editor.on( 'key', function( e ) { 
        console.log('test');
    });
});

Please see: https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#event-key 请参阅: https : //docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#event-key

NOTE: the instanceReady event is not mandatory, you can use pluginsLoaded or just the key event. 注意: instanceReady事件不是强制性的,您可以使用pluginsLoaded或仅使用key事件。 It depends which works the best for your use case. 这取决于哪种方式最适合您的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM