首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具

quill
EN

Stack Overflow用户
提问于 2022-01-05 14:57:45
回答 1查看 709关注 0票数 0

我使用QuillJs作为输入字段,而quill - insert没有在quill内容中插入所选的提到。

代码语言:javascript
运行
复制
  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)
        }
      },
    },
  },
EN

回答 1

Stack Overflow用户

发布于 2022-01-28 08:39:42

代码语言:javascript
运行
复制
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);
         }
       },
       []
     ),
   },

使用这个

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70595010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档