上传图片:无法读取未定义的属性“ setCustomData” [英] Upload Image: Cannot read property 'setCustomData' of undefined
问题描述
我正在尝试将上传的图像嵌入编辑器。我的 filebrowserUploadUrl
是 / api / m / image
,它似乎工作正常。单击将其发送到服务器
按钮后,出现如下脚本错误:
I am trying to embed into the editor an uploaded image. My filebrowserUploadUrl
is /api/m/image
and it seems to be working fine. After I clicked the Send it to the Server
button, there is a script error as follows:
image.js?t=H4PG:19 Uncaught TypeError: Cannot read property 'setCustomData'
of undefined
at textInput.onChange (image.js?t=H4PG:19)
at textInput.n (ckeditor.js:10)
at textInput.CKEDITOR.event.CKEDITOR.event.fire (ckeditor.js:12)
at textInput.setValue (ckeditor.js:619)
at textInput.setValue (ckeditor.js:545)
at a.q (ckeditor.js:841)
at ckeditor.js:31
at Object.callFunction (ckeditor.js:31)
at image?CKEditor=editor&CKEditorFuncNum=1&langCode=en:1
上面的最后一行是对 filebrowserUploadUrl
的调用,其响应为:
The last line in the above is the call to filebrowserUploadUrl
and the response from that is:
window.parent.CKEDITOR.tools.callFunction(1,'/images/bulletins.jpg','成功上传');
window.parent.CKEDITOR.tools.callFunction(1, '/images/bulletins.jpg', 'Uploaded successfully');
成功上传消息显示在警报中。
图像信息
选项卡下的预览框未更新。但是,如果我单击确定关闭对话框,则图像(bulletins.jpg)会嵌入到编辑器中。
The Uploaded successfully
message is shown in an alert. The Preview box under Image Info
tab is not updated. But if I clicked OK to close the dialog, the image (bulletins.jpg) is embedded in the editor alright.
是什么原因导致错误以及如何修复
What could be causing the error and how do I fix it?
我发现是什么原因造成的。启动插入图像对话框时,我想设置默认选项卡。我使用以下代码:
I found what was causing it. I wanted to set the default tab when the insert image dialog is launched to the Upload tab. I use the following code:
CKEDITOR.on("dialogDefinition", function(ev) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if (dialogName === "image") {
dialogDefinition.onShow = function() {
this.selectPage("Upload");
}
}
});
使用上述代码时,上传文件时会发生该错误。
When the above code is used, that error happens when a file is uploaded.
推荐答案
我遇到了同样的问题,使用vikram提出的解决方案后,编辑器在将图像链接粘贴到文本中时产生了错误。这里有一个更好的方法,不是完全覆盖默认的 onShow
方法,而是通过以下方式添加更多方法:
I was having same issue, and after using proposed solution from vikram, editor was generating error while pasting image link into the text. Better approach here, not to completely override default onShow
method, but add more to it in the following way:
CKEDITOR.on('dialogDefinition', function (ev) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if (dialogName == 'image') {
var oldOnShow = dialogDefinition.onShow;
var newOnShow = function () {
this.selectPage('Upload');
this.hidePage('Link');
// change tabs order
$('a[title=Upload].cke_dialog_tab').css('float', 'left');
};
dialogDefinition.onShow = function () {
oldOnShow.call(this, arguments);
newOnShow.call(this, arguments);
};
}
});
这篇关于上传图片:无法读取未定义的属性“ setCustomData”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!