【发布时间】:2019-07-05 10:33:44
【问题描述】:
存在textEditor需要插入一些纯文本内容,我尝试使用EditorState.push方法,我认为它适合这种情况。 我尝试这样的事情:
const { ContentState: { createFromText }, EditorState: { createWithContent, push }} = DraftJS;
export const pushTextToCurrentEditorState = (text, editorState) => {
const textContentState = createFromText(text);
const newEditorState = push(editorState, textContentState, 'insert-characters');
// debugger;
console.log(editorStateToJSON(editorState))
console.log(editorStateToJSON(newEditorState))
return JSON.parse(editorStateToJSON(newEditorState));
}
结果是newEditorState不是合并状态,而是替换一个,旧的editorState丢失,newEditorState变成了全新的东西,就像从text创建一样。
这里有什么错误的用法吗?还是有其他方法可以解决问题?
【问题讨论】:
标签: draftjs react-draft-wysiwyg