On my webpage, I have an editorjs. The user types in the information, and it is saved into my mongodb (as JSON). If I want to edit the information, I'm trying to get that information from the database and load it back into the editorjs. I've tried a couple different thing; none of which are working. This is what I have in my editorjs.js file:
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);
});
I'm open to suggestions.
I said this in the comments but i will say it here so others can see it more clearly when they come to this post. He was missing JSON.parse()
to parse the JSON.