在我的网页上,我有一个 editorjs。用户输入信息,并将其保存到我的 mongodb 中(作为 JSON)。如果我想编辑信息,我会尝试从数据库中获取该信息并将其加载回 editorjs。我尝试了几种不同的方法;这些都不起作用。这就是我的 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);
});
我愿意接受建议。