如何再次销毁并重新初始化CKEDITOR? [英] How to Destroy and Reinitialize CKEDITOR Again?
本文介绍了如何再次销毁并重新初始化CKEDITOR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的代码销毁编辑器实例.
I use the below code to destroy the editor instance.
editor.destroy();
此后,我尝试使用以下代码初始化CKEditor并设置内容.
After this, I try to initialize CKEditor and set content using the below code.
CKEDITOR.replace('editor1');
CKEDITOR.instances['editor1'].setData("MY HTML DATA");
但是当我这样做时,只会显示空的HTML页面.
But when I am doing like this only the empty HTML page is Shown.
我该如何以正确的方式做到这一点?
How can I do this in a Correct Way?
推荐答案
您描述的操作需要时间才能完成,因此请使用事件来控制编辑器的创建和销毁时间:
Operations you have described require time to complete thus please use events to control when editor gets created and destroyed:
- https://docs.ckeditor.com/ckeditor4 /latest/api/CKEDITOR_editor.html#event-instanceReady
-
https://docs.ckeditor. com/ckeditor4/latest/api/CKEDITOR.html#event-instanceDestroyed
var editor = CKEDITOR.replace( 'editor1', {
language: 'en'
});
// Recreate editor after it has been destroyed
CKEDITOR.on( 'instanceDestroyed', function() {
CKEDITOR.replace('editor1');
} );
// Set editor data after it has been created
CKEDITOR.on( 'instanceReady', function( evt ) {
evt.editor.setData("MY HTML DATA");
} );
这篇关于如何再次销毁并重新初始化CKEDITOR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文