【问题标题】:jquery.mention Default Textjquery.mention 默认文本
【发布时间】:2017-12-07 05:47:14
【问题描述】:

我正在尝试实现 jquery.mentions,以便在输入 @ 符号时在系统中提示用户。

一切正常,使用 Ajax 查询填充列表。

但是,对于编辑现有的 cmets,我正在苦苦挣扎。

我已将默认文本设置为之前生成的有效值,但无法正确显示。

渲染的值为

@[Peter Jones](contact:200)

显示为 Peter Jones

如果我将此设置为默认文本,它会显示为 @Peter Jones(显示 @ 符号)

这是一个错误吗?有人解决了吗?

我的代码如下

$(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));
      });
    }) ;


  });

【问题讨论】:

    标签: jquery mentionsinput.js


    【解决方案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();
        }
    

    用多个标签测试,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-30
      • 2011-07-11
      • 2011-06-30
      • 2012-11-13
      相关资源
      最近更新 更多