正确销毁ckeditor实例

时间:2015-09-07 06:16:27

标签: ckeditor destroy

使用版本4.4.7

我的CKEDITOR加载到页面中打开的模态窗口中。我注意到当我重新打开模态时,编辑器不会加载。解决方案是销毁实例,然后在textarea上重新应用它。

但我似乎无法正确销毁它。基于this answer我尝试了以下所有尝试,但我一直收到错误:

def build(env, target, source):
    old = target[0].get_stored_info()
    old = old.binfo
    old.prepare_dependencies()
    old_bkids = old.bsources + old.bdepends + old.bimplicit
    old_bkidsigs = old.bsourcesigs + old.bdependsigs + old.bimplicitsigs
    osig = dict(zip(old_bkids, old_bkidsigs))

    for src_file, info in osig.iteritems():
        print str(src_file) + ' change status: ' + str(src_file.changed_since_last_build(target[0], info))

我尝试过以下内容(为了简单起见,我将所有尝试合并到一个代码块中,但它们是逐个尝试的):

TypeError: a is null
http://domaim/ckeditor/ckeditor.js
Line 778 

更新 我发现只使用var editor = CKEDITOR.instances.mail_message; if (editor) { console.log('instance exists'); // ATTEMPT 1: if (CKEDITOR.instances.mail_message) CKEDITOR.instances.mail_message.destroy(); // -------------------------------------- // ATTEMPT 2: editor.destroy(true); // ------------------------------------- // ATTEMPT 3: CKEDITOR.instances.mail_message.destroy(false); // -------------------------------------- // ATTEMPT 4: for(name in CKEDITOR.instances) { CKEDITOR.instances[name].destroy() } // --------------------------------------- console.log('destroyed'); } // RECREATE: (but code errors out before this, with above-mentioned error. CKEDITOR.replace('mail_message', { toolbar: 'basic' }); 方法重新创建 - 即使没有先破坏。我想这是解决方案。

2 个答案:

答案 0 :(得分:2)

当我想重新加载CKeditor时,我遇到了同样的问题,这段代码解决了我的问题。 要销毁旧实例,

if(CKEDITOR.instances.editor1)
CKEDITOR.instances.editor1.destroy();

我们将检查是否已创建实例。 要重新加载CKeditor,我们将使用

重新创建CKE对象
 CKEDITOR.replace();

答案 1 :(得分:0)

如果你打算重新初始化编辑器,我肯定会想到将true作为参数传递给destroy。我有一个网格,我点击每一行以在jquery模式对话框中提取信息。除非我将“true”作为参数传递,否则我发现setData()不起作用,即使我设置数据而我 还是破坏了之前的实例,旧数据出现在编辑器中。所以使用:

var editor = CKEDITOR.instances ['txt_LH_Update_Body']; if(editor){editor.destroy(true); }

相关问题