0

因此,我无法将存储在 mongdb 中的数据重新显示在编辑器中。

我试过保存这样的数据,但没有任何运气

我使用 Editorjs-parser 包和 Editor.js

这也位于功能组件中


const blogPostSchema = new mongoose.Schema({  
  body: {
    type: Array,
  },
});


import EditorJs from "react-editor-js";
import List from "@editorjs/list";
import LinkTool from "@editorjs/link";
import Header from "@editorjs/header";
import Paragraph from "editorjs-paragraph-with-alignment";
import edjsHTML from "editorjs-html";
import ImageTool from "@editorjs/image";

 const instanceRef = useRef(null);
 let data = {};


const EDITOR_JS_TOOLS = {
  list: List,
  linkTool: LinkTool,
  header: Header,
  paragraph: Paragraph,
  // imageTool: ImageTool,
  image: {
    class: ImageTool,
    config: {
      endpoints: {
        endpoint: "#"
      },
    },
  },
};

 

 <EditorJs
    instanceRef={(instance) => (instanceRef.current = instance)}
    tools={EDITOR_JS_TOOLS}
    data={data}
    onChange={handleChange}
  />


 const handleChange = async () => {
    const savedData = await instanceRef.current.save();
     const HTML = edjsParser.parse(savedData);
     const string = HTML;
     const parse = string.join(" ");
    setBody(parse);

  };

// I then save this to the database

这种方式可以更轻松地从数据库中提取它并显示 html 但我无法将其重新插入编辑器

我如何将数据保存为 Editor.js 从数据库中拉回后可以读取的格式,并将其显示回 Editor.js 中,以便进行编辑和重新保存?

4

0 回答 0