Javascript CKEditor 4.7无法读取属性';在';使用ajax进行未定义、咨询和重置

Javascript CKEditor 4.7无法读取属性';在';使用ajax进行未定义、咨询和重置,javascript,ajax,ckeditor,ckeditor4.x,Javascript,Ajax,Ckeditor,Ckeditor4.x,我对CKEditor版本4.7.0有问题。我正在使用jQueryAjax获取和保存信息。现在的问题是Chrome v 58.0.3029.110在控制台中显示了一个错误-无法读取属性“on”或未定义-,因此我想知道如何解决这个问题,或者是什么类型的问题。这是我的密码: function formService(id) { clearFields(); // clear all the fields in the form // Show and hide form and recor

我对CKEditor版本4.7.0有问题。我正在使用jQueryAjax获取和保存信息。现在的问题是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


有人知道如何解决这个细节吗?任何帮助都将不胜感激!谢谢大家!

尝试使用Try/catch语句销毁CKeditor:

console.log(CKEDITOR.instances['content']);
    if (CKEDITOR.instances['content']) {
       try {
           CKEDITOR.instances['content'].destroy(true);
       } catch (e) { }
    }
    CKEDITOR.replace('content');
    CKEDITOR.instances['content'].setData(content);

我想我已经找到了答案,因为主要的问题是当我加载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;
});
并将其替换为以下行:

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;
});

另一个代码是相同的。

为什么要销毁并重新创建CKEditor实例?你只想更新内容,所以只要在需要时使用
setData()
,并删除
CKReset
函数,这只会让你在这么多
destroy()
replace()
函数中遇到麻烦。我这样做的原因是因为在Chrome中(只使用setData())每次我查阅一条记录时,它会变得越来越慢,控制台会向我抛出有关“过滤器隐藏的项”的信息,例如,首先查阅的是3项,然后我返回列表,查阅新记录,有6项,然后再次查阅8、17、45、100、182、509等,每次都会变得更慢。有时在第一次查询中,不会在编辑器中显示记录的内容。因此,现在我的代码运行良好,但它向我显示了我发布的错误。