Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更新多个CKEditor5实例的源_Javascript_Php_Ckeditor5 - Fatal编程技术网

Javascript 更新多个CKEditor5实例的源

Javascript 更新多个CKEditor5实例的源,javascript,php,ckeditor5,Javascript,Php,Ckeditor5,我在表单上有几个字段。其中一些是简单的输入,另一些是日期时间选择器,一些是编辑器。我手动处理表单submit,因此在将其保存到MySQL数据库之前,我需要手动更新CKEditor实例的源字段以获得所有修改。我将所有实例放在一个数组中(我在Chrome的web developer工具中看到了它的内容),但是当我尝试对这个数组中的一个项使用destroy或updateSourceElement方法时,我会收到“TypeError,item.updateSourceElement不是函数”消息 我使用

我在表单上有几个字段。其中一些是简单的输入,另一些是日期时间选择器,一些是编辑器。我手动处理表单submit,因此在将其保存到MySQL数据库之前,我需要手动更新CKEditor实例的源字段以获得所有修改。我将所有实例放在一个数组中(我在Chrome的web developer工具中看到了它的内容),但是当我尝试对这个数组中的一个项使用destroy或updateSourceElement方法时,我会收到“TypeError,item.updateSourceElement不是函数”消息

我使用以下代码:

const CKeditors = {};

稍后,当我处理onlick事件时,我调用“submitAllCKeditors();”我看到了具有正确ID的数组内容,但是我得到了项的错误。updateSourceElement()

我做错了什么

function createEditor( elementId ) {
return ClassicEditor
.create( document.querySelector( elementId ),
{
    toolbar: [ "heading", "|", "bold", "italic", "link", "bulletedList", "numberedList"]
})
.then( editor => {
    CKeditors[ elementId ] = editor;
})
    .catch( err => console.error( err.stack ) );
}

createEditor("#'.$mezo['mezonev'].'_tartalom");  // $mezo['mezonev'].'_tartalom is the unique name of the input field

function submitAllCKeditors(){
  for (item in CKeditors)
  { 
    item.updateSourceElement();
  }
}