我实际上将DraftJS编辑器的contentState
保存为字符串,使用:JSON.stringify(convertToRaw(editorState.getCurrentContent()))
我的问题是:如何将其显示回来,例如Post。我想我仍然应该使用DraftJS来显示它,因为只有DraftJS可以自然地解析convertFromRaw(JSON.parse(...))
的结果。
问题是例如链接实体在编辑器中无法点击,当我浏览EditorState
和ContentState
的API时,我看不到viewMode
之类的内容或类似的东西,所以我很困惑。
请帮忙。
答案 0 :(得分:0)
我刚看到draft-js-export-html,正是我在寻找的东西。
答案 1 :(得分:0)
您可以通过执行以下操作来显示rawContent:
import { Editor} from 'draft-js';
export default class ShowContent extends React.Component {
constructor(props){
this.state = { editorState: convertFromRaw(JSON.parse(...))};
}
render(){
return <Editor editorState={this.state.editorState} readOnly />
}
}
您对viewMode
属性的假设是正确的。这是&#34; readOnly&#34;您从Draft中导入的Editor组件的属性。