因此,我很难将存储在mongdb中的数据重新显示在编辑器中。
我尝试过这样保存数据,但没有任何运气
我使用了editorjs解析器包和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中,以备编辑和重新保存?
暂无答案!
目前还没有任何答案,快来回答吧!