我想创建一个编辑器,它将启动一个带有样式的 html 元素。
const contents = [
{
"text": "Sample text",
"HTML": "<p style='text-align: center;'><span style='font-size:3em;'><strong>Sample text</strong></span></p>"
},
{
"text": "Sample text2",
"HTML": "<p style='text-align: center;'><span style='font-size:3em;'><strong>Sample text2</strong></span></p>"
}
]
然后我映射它以获取 html 键然后将其设置为状态
const content = contents.map(element => htmlToDraft(element.HTML))
this.state = {
editorState: EditorState.createWithContent(content)
}
然后按状态下html键的元素个数多次渲染编辑器:
this.state.editorState.map((element,index) => {
return
<Editor
defaultEditorState = {element}
onEditorStateChange = {this.onEditorStateChange}
key={index}
/>
})
当我运行它时,它会抛出一个错误 contentState.getBlockMap is not a function