我正在使用react draft wysiwyg库,我希望文本框中输入的值是HTML字符串的形式。
我的州:
editorState: EditorState.createEmpty
editorState={this.state.editorState}
toolbarClassName="toolbarClassName"
wrapperClassName="wrapperClassName"
editorClassName="editorClassName"
onEditorStateChange={this.onEditorStateChange}
/>
我的onChange处理程序:
onEditorStateChange = (editorState) => this.setState({editorState});
以及我的handleSubmit函数:
handleSubmit = async (event) => {
event.preventDefault();
const convertedData =
convertToRaw(this.state.editorState.getCurrentContent())
//Followed by some code about posting to an API
目前,当我看到发布的内容时,它看起来像:
convertedData: {...}
blocks: {...}
0: {key: "174mo", text: "example text" etc... }
1: {key: "5cdsn", text: "example text2" etc... }
包含输入的所有文本格式的数组。
可以把它转换成一个HTML字符串吗?
例如:
"
This is a header
- List item
"