【发布时间】:2016-10-21 03:59:12
【问题描述】:
我有表情符号列表。他们每个人都有自己的unicode。使用 Modifier.insertText(),我想将它们插入到文本中。
_addEmoji(text) {
const { editorState } = this.state;
const selection = editorState.getSelection();
const contentState = editorState.getCurrentContent();
const txt = '&#x' + text + ';';
let nextEditorState = EditorState.createEmpty();
if (selection.isCollapsed()) {
const nextContentState = Modifier.insertText(contentState, selection, txt);
nextEditorState = EditorState.push(
editorState,
nextContentState,
'insert-characters'
);
} else {
const nextContentState = Modifier.replaceText(contentState, selection, text);
nextEditorState = EditorState.push(
editorState,
nextContentState,
'insert-characters'
);
}
this.onChange(nextEditorState);
}
我希望看到????插入到编辑器,但它显示行 😄 代替。
我已将<meta charset="utf-8" /> 插入到<head />,并且表情符号列表完美呈现。主要问题是 Draftjs 编辑器显示原始 unicode 而不是表情符号。
有解决这个问题的想法吗?谢谢。
【问题讨论】:
-
所以你已经在 HTML 中包含了 unicode,现在它可以正常工作了吗?这里有什么问题?,我不明白。
-
字符集应该在 html 文档的头部指定。您使用的是不同的字符集吗?