0

I'm working on a summernote editor and trying to implement the "mention" feature by pulling usernames from a database.

match: /\B@(\w*)$/,                     
            mentions:function(keyword, callback) {
            $.ajax({
                    url: document.location.origin+"/topic/groupusers/"+topic_cat,
                    type: 'GET',
                    success: function(callback) {                       
                        callback = $(callback).filter('.mentiondata').text();                           
                    }       
                });
            },


            search: function (keyword, callback) {
                callback($.grep(this.mentions, function (item) {
                    return item.indexOf(keyword) == 0;
                  }));
            },
            content: function (item) {
                return '@' + item;
            }

The mention attribute needs to have this format: mentions: ['jayden', 'sam', 'alvin', 'david'],

when I console.log callback inside the success function that's what I get. However, it doesn't work on search event and gives me item is undefined error

Grasper
  • 1,293
  • 12
  • 26

1 Answers1

0
  1. Pass keyword or your parameters in mention function while search.
  2. Return value of success in mentions function
 match: /\B@(\w*)$/,
  mentions: function(keyword) {
    $.ajax({
      url: document.location.origin + "/topic/groupusers/" + topic_cat,
      type: 'GET',
      success: function(result) {
        return $(result).filter('.mentiondata').text();
      }
    });
  },
  search: function(keyword, callback) {
    callback($.grep(this.mentions(keyword), function(item) {
      return item.indexOf(keyword) == 0;
    }));
  },
  content: function(item) {
    return '@' + item;
  }

Sample code

Prashant Tapase
  • 2,132
  • 2
  • 25
  • 34