首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在夏季笔记中添加提示词

在夏季笔记中添加提示词
EN

Stack Overflow用户
提问于 2017-05-03 11:03:41
回答 1查看 722关注 0票数 1

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

代码语言:javascript
复制
$(".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;
  }));
 }
}
});

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

代码语言:javascript
复制
$.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”中,或者用"arrayWithWords“的值替换"words”值呢?主要的问题是,在用户可以使用Summernote之前,必须为Summernote中的提示词预定义字典,而且我看不出有任何方法来更新" words“。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-01 14:06:55

我只是在找别的东西的时候偶然发现了这个问题,很抱歉这里的领带柱。如果您还没有弄清楚这一点,您可以只使用回调函数中的arrayWithWords变量来进行提示搜索,而不是使用初始化时定义的单词列表。当搜索运行时,它将使用arrayWithWords的当前值。

代码语言:javascript
复制
$(".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;
  }));
 }
}
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43758221

复制
相关文章

相似问题

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