【问题标题】:CKEditor - Destroy an editor instanceCKEditor - 销毁一个编辑器实例
【发布时间】:2015-12-18 13:33:48
【问题描述】:

我创建了一个带有一些文本的页面,点击某个DIV 会出现一个内联编辑器。

我需要销毁新创建的实例,但我不能。我在CKEditor API the destroy() method 中找到了,但它对我不起作用。 这是我的代码:

HTML

<div id ="0" contenteditable = "true">
    <h1Text</h1>
</div>

<div id ="1" contenteditable = "true">
    <h2>Other text</h2>
</div>

JS

CKEDITOR.disableAutoInline = false; //turn off automatic editor creation first 
var editor = CKEDITOR.inline(idElem); //editor is the editor instance created
if(CKEDITOR.instances.editor != 'undefined' && editor != null) { 
    CKEDITOR.instances.editor.destroy(); //generates the error
}

错误是:Uncaught TypeError: Cannot read property 'destroy' of undefined

事实上,以下打印产生了这些结果:

console.log("editor: " + editor); //prints "editor: [object Object]"
console.log("CKEDITOR.instances.editor: " + CKEDITOR.instances.editor); //prints "CKEDITOR.instances.editor: undefined"

为什么?如何获取刚刚创建的编辑器实例以便随后销毁?

【问题讨论】:

  • CKEDITOR.instances.editor != 'undefined' - 为什么要引用?实际上是undefined。你不能只使用editor.destroy()吗?
  • @raina77ow editor.destroy() 产生同样的错误
  • 那你能显示 HTML 吗?有一组有限的元素可以转换为 CKEditor 实例。
  • 转念一想,这里确实有问题:从source 来看,editor 可以是 null 或 CKEditor 实例,在任何情况下都不应该是 undefined。你能调试CKEDITOR.inline 看看发生了什么吗?
  • @raina77ow 我添加了 html 帖子。显然编辑器与 DIV 相关联。

标签: javascript ckeditor instance destroy


【解决方案1】:

那 (CKEDITOR.instances) 是一个实例数组,你应该循环它来销毁每个实例:

for (key in CKEDITOR.instances) {
    CKEDITOR.instances[key].destroy(true);
}

【讨论】:

  • 这是我需要的东西,但它在控制台中说:editor-incorrect-destroy 并在销毁它后删除所有 ck 编辑器+官方网站将此问题声明为:编辑器在它之前被销毁已完全初始化。
  • 仍然收到警告:[CKEDITOR] 错误代码:editor-incorrect-destroy。
猜你喜欢
  • 2011-04-06
  • 1970-01-01
  • 2015-04-14
  • 2019-06-16
  • 2014-03-25
  • 1970-01-01
  • 2019-03-30
  • 2019-02-22
  • 2019-02-19
相关资源
最近更新 更多