我使用QuillJs作为输入字段,而quill - insert没有在quill内容中插入所选的提到。
quillEditor = new Quill(editor, {
formats: ['mention'],
modules: {
mention: {
allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/,
mentionDenotationChars: ['#'],
source: function (searchTerm, renderList, mentionChar) {
let values
if (mentionChar === '#') {
values = tags.map((i) => {
return { value: i.name, id: i.name }
})
}
if (searchTerm.length === 0) {
renderList(values, searchTerm)
} else {
const matches = []
for (let i = 0; i < values.length; i++)
if (~values[i].value.toLowerCase().indexOf(searchTerm.toLowerCase())) matches.push(values[i])
renderList(matches, searchTerm)
}
},
},
},
发布于 2022-01-28 08:39:42
mention: {
allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/,
mentionDenotationChars: ['{', '}', '#'],
source: useCallback(
(searchTerm: string, renderItem: any, mentionChar: string) => {
let values;
if (mentionChar === '{' || mentionChar === '}') {
values = atValues;
} else if (mentionChar === '#') {
values = hashValues;
}
if (searchTerm.length === 0) {
renderItem(values, searchTerm);
} else if (values) {
const matches = [];
for (let i = 0; i < values.length; i += 1)
if (
values[i].value.toLowerCase().indexOf(searchTerm.toLowerCase())
)
matches.push(`{${values[i]}`);
renderItem(matches, searchTerm);
}
},
[]
),
},
使用这个
https://stackoverflow.com/questions/70595010
复制相似问题