【问题标题】:Add hint words into summernote在summernote中添加提示词
【发布时间】:2017-10-01 04:15:35
【问题描述】:

我能否以某种方式将单词添加到从服务器获取的 Summernote 字典中?默认情况下,Summernote 支持名为“hint”的选项,您可以在“words”中为提示词预定义字典,如下所示:

$(".hint2basic").summernote({
height: 100,
toolbar: false,
placeholder: 'type with apple, orange, watermelon and lemon',
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;
  }));
 }
}
});

但是如果我想添加一些我从服务器获得的其他单词怎么办:

$.ajax({
            beforeSend: function(request) {
            request.setRequestHeader("Accept", "application/ld+json");},
            url:'MY URL', 
            type:'POST',
            data:JSON.stringify(jsonld),
            success: function(response)
            {
                //here must be something, e.g.
                var arrayWithWords = response;
            }
      });

在“arrayWithWords”中,我现在有一个字符串,例如“汽车”、“房子”、“包”。

我现在应该怎么做才能将这个“arrayWithWords”添加到 Summernote 的“words”中,或者只是将“words”值替换为“arrayWithWords”的值?主要问题是在用户可以使用 Summernote 之前,您必须在 Summernote 中为提示词预定义字典,而我看不到任何更新“单词”的方法。

【问题讨论】:

    标签: javascript html summernote


    【解决方案1】:

    我只是在寻找其他东西时偶然发现了这个问题,所以对这里的死灵帖子感到抱歉。如果您还没有弄清楚这一点,您可以在回调函数中使用您的 arrayWithWords 变量进行提示搜索,而不是使用在初始化时定义的单词列表。任何时候运行搜索,都会使用 arrayWithWords 的当前值。

    $(".hint2basic").summernote({
    height: 100,
    toolbar: false,
    placeholder: 'type with apple, orange, watermelon and lemon',
    hint: {
     match: /\b(\w{1,})$/,
     search: function (keyword, callback) {
      callback($.grep(arrayWithWords, function (item) {
        return item.indexOf(keyword) === 0;
      }));
     }
    }
    });
    

    【讨论】:

      猜你喜欢
      • 2014-10-02
      • 2016-07-04
      • 2017-08-01
      • 2016-11-22
      • 1970-01-01
      • 2020-05-21
      • 2016-02-01
      • 2020-03-27
      • 2016-09-13
      相关资源
      最近更新 更多