javascript - 在summernote中添加提示词

标签 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”中,我现在有一个字符串,例如“车”、“房子”、“包”。

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

最佳答案

我只是在寻找其他东西时偶然发现了这个问题,所以,对于这里的死灵帖子感到抱歉。如果您还没有弄清楚这一点,您可以在回调函数中使用 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;
  }));
 }
}
});

关于javascript - 在summernote中添加提示词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43758221/

相关文章:

javascript - 我可以用 JS 禁用水平鼠标滚动吗?

javascript - 当我添加 javascript 时,Laravel Maddhatter fullcalendar 不工作

Javascript--统计每个字符串出现的频率并从大到小打印出来

python - django-summernote 设置配置仅失败语言部分

javascript - 如何设置编辑器的高度并同时填充?

javascript - Redux thunk 在下一个 Action 之前未解析 + then 不是函数或分派(dispatch)未定义

javascript - 无法在 React 组件中编写 HTML

html - 纯 CSS 选择菜单/下拉菜单 : How to make custom right arrow?

html - 使背景图像在整个站点 HTML/CSS 中保持一致

android - 防止在移动版 Firefox 中输入字段焦点后放大