2017-07-07 5 views
0

私はsummernoteエディタで作業していて、データベースからユーザー名を取り出すことによって "言及"機能を実装しようとしています。 mentions: ['jayden', 'sam', 'alvin', 'david'],AJAXコールから配列を取得する

は私が何を得るの成功関数内callbackをCONSOLE.LOG:

match: /\[email protected](\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; 
      } 

言及属性は、この形式を持っている必要があります。ただし、検索イベントでは機能しません。item is undefinedエラー

+0

に言及していますか?非同期コールバックを適切に処理していないようです。 – Carcigenicate

+0

yが検索機能で言及していますか? 'これは何? –

+0

@PrashantTapase、それは関数全体を出力します – Grasper

答えて

0
  1. 検索中にキーワードまたはパラメータを渡すと機能します。成功の
  2. 戻り値は、関数あなたが検索呼ぶのです
match: /\[email protected](\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

+0

\t jquery.min.jsに「a is undefined」と表示されています – Grasper

関連する問題