首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将json数据加载到editorjs中

将json数据加载到editorjs中
EN

Stack Overflow用户
提问于 2021-09-16 14:06:19
回答 1查看 649关注 0票数 0

在我的网页上我有一篇社论。用户输入信息,并将其保存到我的mongodb (作为JSON)中。如果我想编辑这些信息,我会尝试从数据库中获取这些信息,并将其加载到编辑器中。我试过几种不同的方法,但都没有用。这就是我的editorjs.js文件中的内容:

代码语言:javascript
复制
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);
});

我愿意接受建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-16 14:20:42

我在评论中这样说过,但我会在这里说出来,这样其他人来这篇文章的时候就能看得更清楚了。他缺少JSON.parse()来解析JSON。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69209965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档