我的 CKEditor 版本 4.7.0 有问题。我正在使用 jQuery ajax 来获取和保存信息。现在的问题是 Chrome v 58.0.3029.110 在控制台中显示错误 - 无法读取属性“on”或未定义 - 所以我想知道如何解决这个问题或者是什么类型的问题。这是我的代码:
function formService(id)
{
clearFields(); // clear all the fields in the form
// Show and hide form and record listing
$("#areaForm").css("display", "block");
$("#areaList").css("display", "none");
if (id != 0)
{
$("#id").val(id);
$.ajax({
url: 'admin/'+controller+'/ajaxQueryRecord',
type: 'post',
dataType: 'json', // to get a json object with all fields with information
data: {id: id},
})
.done(function(json) {
CKReset(json.content); // A function below of this code
delete json.content;
// A global function that extract information and are assigned to their fields
// in the form
assign_JSON_to_Fields(json);
$("#btnSubmit").val("Update"); // Only to change the text of the button
})
.fail(function() {
console.log("error");
});
} else {
$("#btnSubmit").val("Add");
}//if
}//fn
// Clean all the fields in the form
function clearFields()
{
$("#frmService input[type=text]").val("");
$("#id").val(0);
$('textarea').val('');
CKReset('');
}//fn
// Function that reset content destroying CKEditor instance
// and create (replace) a new one
function CKReset(content)
{
console.log(CKEDITOR.instances['content']);
if (CKEDITOR.instances['content']) {
CKEDITOR.instances['content'].destroy(true);
}//if
CKEDITOR.replace('content');
CKEDITOR.instances['content'].setData(content);
}//fn
有人知道如何解决这个细节吗?任何帮助将不胜感激!谢谢!
最佳答案
我想我已经找到了答案,因为主要问题是当我加载ajax数据时CKEditor还没有准备好,并且无法识别“content”字段,然后控制台抛出错误。但是使用这行代码,我加载内容没有任何问题,并且脚本会等待 CKEditor 实例准备就绪:
我必须删除这一行:
CKReset(json.content); // A function below of this code
delete json.content;
并将它们替换为以下行:
CKEDITOR.instances['content'].on("instanceReady", function(event) {
CKReset(json.content);
delete json.content;
});
其他代码相同。
关于javascript - CKEditor 4.7 无法读取未定义的属性 'on',请用ajax咨询并重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44266538/