在我的网页上我有一篇社论。用户输入信息,并将其保存到我的mongodb (作为JSON)中。如果我想编辑这些信息,我会尝试从数据库中获取这些信息,并将其加载到编辑器中。我试过几种不同的方法,但都没有用。这就是我的editorjs.js文件中的内容:
const description = data.description; // My JSON that was saved.
console.log(description); // So far so good, console logs just what should be expected.
const editor = new EditorJS({
holderID: 'editorjs',
tools: {
// toolbar configuration here
},
data: description // This doesn't work, however if I copy and paste
// the data that the console logged from earlier,
// it loads correctly into the editorjs
});
// My newest attempt here
editor.isReady.then(() => {
console.log('ok'); // Works so far
console.log(description); // Also works, logging the same information as earlier
editor.render({
description
});
}).catch((err) => {
console.log(err);
});我愿意接受建议。
发布于 2021-09-16 14:20:42
我在评论中这样说过,但我会在这里说出来,这样其他人来这篇文章的时候就能看得更清楚了。他缺少JSON.parse()来解析JSON。
https://stackoverflow.com/questions/69209965
复制相似问题