【问题标题】:Quill-mention does not insert the selected mention in quill contentQuill-mention 不会在 quill 内容中插入选定的提及
【发布时间】:2022-01-05 14:57:45
【问题描述】:

我使用 QuillJs 作为输入字段,并且 quill-mention 不会在 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)
        }
      },
    },
  },

【问题讨论】:

    标签: svelte quill mention


    【解决方案1】:
    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);
             }
           },
           []
         ),
       },
    

    使用这个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2022-07-14
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 1970-01-01
      相关资源
      最近更新 更多