在summernote中添加提示词

时间:2017-05-03 11:03:41

标签: javascript html summernote

我可以以某种方式在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"我现在有一个字符串,例如" car"," house"," bag"。

我现在应该做些什么来添加这个" arrayWithWords"进入Summernote"单词"或者只是替换"单词"值为" arrayWithWords"?主要问题是,在用户可以使用Summernote之前,您必须在Summernote中为提示词预定义字典,并且我没有看到任何更新"单词"的方法。你有什么想法吗?

1 个答案:

答案 0 :(得分: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;
  }));
 }
}
});