【问题标题】:Using ! or @ in Summernote hint content使用 !或 @ 在 Summernote 提示内容中
【发布时间】:2017-08-01 06:30:48
【问题描述】:

在我的summernote提示选项中,我有以下内容

hint: {
    match: /\B[@!](\w*)$/,
    search: function (keyword, callback) {
        callback($.grep(mentions, function (i) {
            user = mentionData[i];
            return user.name.indexOf(keyword) === 0;
        }));
    },
    template: function...
    content: function (i) {
        var user = mentionData[i];
        return $('<span>@' + user.username + '</span>')[0];
    }
}

我希望能够插入 @ 或 !符号(无论用户使用哪个启动提示)到内容选项中。有没有办法将关键字传递给内容函数?或者有没有特定于summernote的方法来做到这一点?

【问题讨论】:

    标签: javascript summernote


    【解决方案1】:

    可以使用数组提示,例如:

    hint:[
          {
            words: ['apple', 'orange', 'watermelon', 'lemon'],
            match: /\b(\w{1,})$/,
            search: function (keyword, callback) {
            callback($.grep(this.words, function (item) {
             return item.indexOf(keyword) === 0;
            }));
          },
          {
            mentions: ['jayden', 'sam', 'alvin', 'david'],
            match: /\B@(\w*)$/,
            search: function (keyword, callback) {
             callback($.grep(this.mentions, function (item) {
              return item.indexOf(keyword) == 0;
             }));
            },
            content: function (item) {
             return '@' + item;
            }    
          }
        ]
      }
    },
    

    【讨论】:

      猜你喜欢
      • 2017-10-01
      • 2017-01-05
      • 2020-04-14
      • 2016-08-15
      • 2018-10-14
      • 1970-01-01
      • 2016-11-05
      • 2015-05-31
      • 2020-06-03
      相关资源
      最近更新 更多