Javascript 内容状态在数据转换后丢失自定义样式
我需要将序列化内容状态存储到本地存储中。我正在尝试转换数据,并使用数据转换助手将其恢复。状态包含一些自定义内联样式。这是一个示例代码:Javascript 内容状态在数据转换后丢失自定义样式,javascript,reactjs,draftjs,Javascript,Reactjs,Draftjs,我需要将序列化内容状态存储到本地存储中。我正在尝试转换数据,并使用数据转换助手将其恢复。状态包含一些自定义内联样式。这是一个示例代码: var oldEditorState=this.state.editorState; var editorState=RichUtils.toggleInlineStyle(oldEditorState,myCustomStyle); editorState=RichUtils.toggleInlineStyle(editorState,“粗体”) var co
var oldEditorState=this.state.editorState;
var editorState=RichUtils.toggleInlineStyle(oldEditorState,myCustomStyle);
editorState=RichUtils.toggleInlineStyle(editorState,“粗体”)
var contentState=editorState.getCurrentContent();
var rawContent=DraftJs.convertToRaw(contentState);
var contentBlocks=DraftJs.convertFromRaw(rawContent);
var contentState=contentState.createFromBlockArray(contentBlocks);
var nextEditorState=EditorState.createWithContent(contentState);
this.setState({editorState:nextEditorState});
不幸的是,这种方法会丢失自定义样式。但它可以与预定义的(例如,粗体)配合使用。为什么?如何解决此问题?此问题已在较新版本的draftjs中解决