Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 内容状态在数据转换后丢失自定义样式_Javascript_Reactjs_Draftjs - Fatal编程技术网

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中解决