0

请帮我。我有这样的代码,但是在更改状态时出现问题,消息错误是'Uncaught Error: Got unexpected null or undefined (...)'

var contentState, editorState, text;
text = this.state.text;
contentState = ContentState.createFromBlockArray(Draft.convertFromHTML(text));
editorState = EditorState.createWithContent(contentState);
this.setState({
  editorState: editorState
});
4

1 回答 1

0

为什么不直接从文档中复制代码

const sampleMarkup =
  '<b>Bold text</b>, <i>Italic text</i><br/ ><br />' +
  '<a href="http://www.facebook.com">Example link</a><br /><br/ >' +
  '<img src="image.png" height="112" width="200" />';

const blocksFromHTML = convertFromHTML(sampleMarkup);
const state = ContentState.createFromBlockArray(
  blocksFromHTML.contentBlocks,
  blocksFromHTML.entityMap,
);

this.state = {
  editorState: EditorState.createWithContent(state),
};
于 2016-11-29T10:06:35.983 回答