我正在我的应用中实施CKEditor
。当我试图将CKEditor
实例化到textarea时,我收到了错误
Cannot read property 'getSelection' of undefined
在ckeditor的下面一行
getNative: function() {
return void 0 !== this._.cache.nativeSel ? this._.cache.nativeSel : this._.cache.nativeSel = B ? this.document.$.selection : this.document.getWindow().$.getSelection() }
非常感谢任何帮助。
答案 0 :(得分:2)
然后我开始出现这个错误。
TypeError: Cannot read property 'getSelection' of undefined
at CKEDITOR.dom.selection.getNative (ckeditor.js:448)
at new CKEDITOR.dom.selection (ckeditor.js:446)
at a.CKEDITOR.editor.getSelection (ckeditor.js:443)
at new CKEDITOR.plugins.undo.Image (ckeditor.js:1182)
at CKEDITOR.plugins.undo.UndoManager.save (ckeditor.js:1177)
at a.<anonymous> (ckeditor.js:1173)
at a.n (ckeditor.js:10)
at a.CKEDITOR.event.CKEDITOR.event.fire (ckeditor.js:12)
at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:13)
at a.setData (ckeditor.js:275)
对我来说解决方案很简单,告诉计算机在关闭对话框/模态时销毁ckeditor实例。简单!..现在像魅力一样工作=)
$mdDialog.show({
parent: parentEl,
targetEvent: $event,
templateUrl: '/md-templates/blog-article.html',
controller: DialogController,
scope: $scope,
preserveScope: true,
onRemoving: function (event, removePromise) {
if (CKEDITOR.instances.body) CKEDITOR.instances.body.destroy();
}
});
答案 1 :(得分:0)
我遇到了同样的错误,我通过初始化CKEditor解决了
$(document).function(ready());
$(document).ready(function () {
CKEDITOR.replace('editor1', {
language: 'tr',
height: '300'
});
});
我认为在页面加载之前进行初始化时,找不到dom元素(文本区域)
答案 2 :(得分:0)
您可以尝试
CKEditor.destroy();
答案 3 :(得分:0)
这可能是您的应用程序在准备好编辑器之前尝试访问并设置CKEditor的数据。这可能是争用条件的结果,导致错误是间歇性的。您可以采取一些措施来防止此问题。
首先,使用CKEditor endorsed方法测试编辑器是否首先loaded
。
if ( CKEDITOR.status == 'loaded' ) {
// The API can now be fully used.
doSomething();
} else {
// Wait for the full core to be loaded and fire its loading.
CKEDITOR.on( 'load', doSomething );
CKEDITOR.loadFullCore && CKEDITOR.loadFullCore();
}
第二,如果您无法控制与设置编辑器值相关的时间,则可以将CKEDITOR.dom.window
对象包装在async
/ await
Promise
中测试是否首先加载编辑器,如果未加载,则测试是否要加载编辑器,然后完成设置值。 (请注意,此代码尚未经过全面测试)
CKEDITOR.dom.window = (function(window) {
if ( CKEDITOR.status == 'loaded' ) {
// The API can now be fully used.
return window;
} else {
return (async function() {
return await function() {
return new Promise(resolve => {
CKEDITOR.on( 'load', () => {
resolve(window);
});
});
};
})();
CKEDITOR.loadFullCore && CKEDITOR.loadFullCore();
}
})(CKEDITOR.dom.window);
答案 4 :(得分:-4)
将ckeditor.js中的函数f。$。onload更改为下面的
f.$.onload=function(){var toutMs =5000;
if(CKEDITOR.document.getHead().$.childElementCount > 6)
{
toutMs=0;
}
setTimeout(function(){
A(b,!0)
},toutMs)
}