偶然发现了这个很酷的文本编辑器,draft.js通过 Facebook 。 我尝试按照 Github 中的示例进行操作,但我想创建一个包含内容的编辑器而不是空编辑器。
var EditorState = Draft.EditorState;
var RichEditor = React.createClass({
getInitialState(){
return {editorState: EditorState.createWithContent("Hello")}
//the example use this code to createEmpty editor
// return ({editorState: EditorState.createEmpty()})
}
});
当我运行它时,它会抛出一个错误,并显示以下消息“Uncaught TypeError: contentState.getBlockMap is not a function”。
最佳答案
EditorState.createWithContent 的第一个参数是一个 ContentState
,而不是一个字符串。您需要导入ContentState
var EditorState = Draft.EditorState;
var ContentState = Draft.ContentState;
使用ContentState.createFromText并将结果传递给EditorState.createWithContent .
return {
editorState: EditorState.createWithContent(ContentState.createFromText('Hello'))
};
关于reactjs - Draftjs 如何启动内容编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35884112/