CKEditor + Bootstrap modal + LayoutManager 插件, selection.getStartElement() returns null

CKEditor + Bootstrap modal + LayoutManager plugin, selection.getStartElement() returns null

点击我的应用程序的一堆按钮允许创建不同的自定义 CKEditor 实例,此外,在 textarea 内创建了一个带有布局管理器插件的网格。创建的编辑器驻留在 bootstrap 模式的主体内。

第一次单击其中一个按钮时,一切正常,我可以获得正确的开始元素,并且可以从我的应用程序正确访问可编辑区域。 当我处理模态时,我也销毁了 CKEditor 的实例和关联的视图(该应用程序还涉及 Backbone.js)被删除:

$('#tallModal').one('hidden.bs.modal', function(e) {
                if (this.ckeditor) {
                    CKEDITOR.instances[this.model.get("uniqueId")].destroy();
                    this.ckeditor = null;
                    }
                this.view.close();
            }.bind(this)).modal('hide');

this.ckeditor创建如下:

this.ckeditor = $("#"+ this.model.get("uniqueId")).ckeditor(config.rte.ckeditor, $deferred.resolve).editor;

当我点击另一个按钮时,模态显示正确的编辑器实例,但是当我的代码到达这一行时(this._editorthis.ckeditor 的别名):

return this._editor.getSelection().getStartElement();

出现以下错误:

TypeError: Cannot read property 'getStartElement' of null

调试代码我发现,当编辑器被销毁然后再次创建时,编辑器对象 (this._editor) 具有 属性 status="destroyed",而当一切正常时 status="ready"

我尝试了这个解决方案 和许多其他解决方案都没有成功,无论如何都会调用行 this.$element.trigger( 'focus' );

我找到了自己的答案:

this._editor = CKEDITOR.instances[this.model.get("uniqueId")];

我在 Backbone.Viewinitialize 方法中有这一行,但这样我只能获得对已销毁实例的引用。

this._editor 中的编辑器实例必须是 "refreshed" 每次我想做一些结果为:

 return this._editor.getSelection().getStartElement();