我一直在使用Facebook的draft-js,但实际上我不知道如何获取编辑器的html输出。在下面的示例中,console.log输出了一些_map
属性,但它们似乎并没有包含我的实际内容?
class ContentContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
value: '',
editorState: EditorState.createEmpty()
};
this.onChange = (editorState) => this.setState({editorState});
this.createContent = this.createContent.bind(this);
}
createContent() {
console.log(this.state.editorState.getCurrentContent());
}
render() {
const {editorState} = this.state;
const { content } = this.props;
return (
<Template>
<br /><br /><br />
<ContentList content={content} />
<div className="content__editor">
<Editor editorState={editorState} onChange={this.onChange} ref="content"/>
</div>
<FormButton text="Create" onClick={this.createContent.bind(this)} />
</Template>
);
}
}
import { stateToHTML } from "draft-js-export-html";
导入它,然后将其用作onChange={(e: EditorState) => { onTranslationChange && onTranslationChange( stateToHTML(e.getCurrentContent()), localization.language ); }}
。 - danivicario