我正在尝试保存editorState到数据库并显示回编辑器。对于这件事,我遵循了这个答案
现在,当我尝试获取当前内容并使用 永久保存它时convertToRaw,它工作正常。但是当我尝试使用这些数据并将原始数据转换为contentState使用时convertFromRaw,出现以下错误:
未捕获的类型错误:contentState.getBlockMap 不是函数
editorState这是我从保存状态转换的代码:
{
const convertedState = convertFromRaw(JSON.parse(value))
const editorValue = EditorState.createWithContent(convertedState);
}
Run Code Online (Sandbox Code Playgroud)
这样,它会在编辑器中显示数据,但是当我向富编辑器中输入内容时。它提示:
未捕获的类型错误:contentState.getBlockMap 不是函数
附:使用draft-js: '0.10.5'
小智 6
EditorState是一个不可变记录,代表 Draft.js 编辑器的整个状态,其中包括ContentState,但它们是不同的东西。
EditorState 对象维护由 ContentState 对象组成的撤消和重做堆栈。
您可能正在寻找的是:
const convertedState = convertFromRaw(JSON.parse(value))
const editorValue = EditorState.createWithContent(convertedState.getCurrentContent());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9990 次 |
| 最近记录: |