2017-07-03 11 views
0

@記号を入力するときにシステム内のユーザーをsugestingするためにjquery.mentionsを実装しようとしています。jquery.mentionデフォルトのテキスト

すべてがうまくいき、Ajaxクエリを使用してリストを作成しています。

しかし、既存のコメントを編集するには苦労しています。

既定のテキストを以前に生成された有効な値に設定しましたが、正しく表示されません。

レンダリングされた値が、私はデフォルトのテキストに設定すると、それは(@記号を示す)@Peter・ジョーンズのように表示されるピーター・ジョーンズ

として表示さ

@[Peter Jones](contact:200) 

ある

これはバグですか?誰にも修正がありますか?

$(function() { 

    $('textarea.mention').mentionsInput({ 
     defaultValue : '@[Peter Jones](contact:200)', 
     onDataRequest:function (mode, query, callback) { 
      $.getJSON('Ajax/GetUserTags.php', function(responseData) { 
      responseData = _.filter(responseData, function(item) { return item.name.toLowerCase().indexOf(query.toLowerCase()) > -1 }); 
      callback.call(this, responseData); 
      }); 
     } 
    }); 

    $('.get-syntax-text').click(function() { 
     $('textarea.mention').mentionsInput('val', function(text) { 
     alert(text); 
     }); 
    }); 

    $('.get-mentions').click(function() { 
     $('textarea.mention').mentionsInput('getMentions', function(data) { 
     alert(JSON.stringify(data)); 
     }); 
    }) ; 


    }); 

答えて

1

を次のように

私のコードは、私がjquery.mentionsinputに見て、resetInput機能を調整しています。

newMentionTextを設定するとき、@記号であるMatch [1]要素を削除しました。

function resetInput(currentVal) { 
     mentionsCollection = []; 
     var mentionText = utils.htmlEncode(currentVal); 
     var regex = new RegExp("(" + settings.triggerChar + ")\\[(.*?)\\]\\((.*?):(.*?)\\)", "gi"); 
     var match, newMentionText = mentionText; 
     while ((match = regex.exec(mentionText)) != null) { 
      //alert(match[0] + "\n" + match[1] + "\n" + match[2]); 
      //newMentionText = newMentionText.replace(match[0], match[1] + match[2]); 
      newMentionText = newMentionText.replace(match[0], match[2]); 
      mentionsCollection.push({ 'id': match[4], 'type': match[3], 'value': match[2], 'trigger': match[1] }); 
     } 
     elmInputBox.val(newMentionText); 
     updateValues(); 
    } 

複数のタグでテストしても問題ありません。

+0

これは非常に役に立ちました。ありがとうございました! –

関連する問題