【问题标题】:Summernote get mentions from php with many valueSummernote 从 php 中获得很多价值
【发布时间】:2020-06-25 13:05:38
【问题描述】:

我将 SummerNote 编辑器添加到我的网站中,并尝试提及但我遇到了一个问题:

如果这样离开它就可以正常工作: `

 jQuery(document).ready(function(e) {
            $("#content").summernote({
                dialogsInBody: true,
                height: 150,
                toolbar: [
                    ['font', ['bold', 'italic', 'underline', 'clear']],
                    ['color', ['color']],
                    ['para', ['ul', 'ol', 'paragraph']],
                    ['table', ['table']],
                    ['insert', ['link', 'picture', 'video', 'hr']]
                  ],
                  hint: {
                  mentions: [{"userid":"25","name":"Checkbnotif","dir":"201910","avatar":"","slug":"checkbnotif"}],
                        match: /\B@(\w*)$/,
                        search: function (keyword, callback) {
                            callback($.grep(this.mentions, function (item) {
                                return item.slug.indexOf(keyword) == 0;
                            }));
                        },
                        template: function (item) {
                            return '<img src="'+ baseURL + 'assets/userstore/'+ item.dir +'/'+  item.avatar + '" width="20" />' + item.name + '';
                        },
                        content: function (item) {
                            return $('<span><b><span class="href" data-id="'+item.usserid+'">@' + item.name + '</span>&nbsp;</b></span>')[0];
                        }
                    }
            });
});

`

但是当我使用 phpfile 进行提及时,它不起作用: `

  jQuery(document).ready(function(e) {
            $("#content").summernote({
                dialogsInBody: true,
                height: 150,
                toolbar: [
                    ['font', ['bold', 'italic', 'underline', 'clear']],
                    ['color', ['color']],
                    ['para', ['ul', 'ol', 'paragraph']],
                    ['table', ['table']],
                    ['insert', ['link', 'picture', 'video', 'hr']]
                  ],
                  hint: {

                        match: /\B@(\w*)$/,
                        mentions: function(keyword, callback) {
                             $.ajax({
                                 url: baseURL + "thanh_vien/userjson/" + keyword,
                                 type: 'get',
                                 dataType: "json",   
                                 async: false
                             }).done(callback);
                         },

                        search: function (keyword, callback) {
                            callback($.grep(this.mentions, function (item) {
                                return item.slug.indexOf(keyword) == 0;
                            }));
                        },
                        template: function (item) {
                            return '<img src="'+ baseURL + 'assets/userstore/'+ item.dir +'/'+  item.avatar + '" width="20" />' + item.name + '';
                        },
                        content: function (item) {
                            return $('<span><b><span class="href" data-id="'+item.usserid+'">@' + item.name + '</span>&nbsp;</b></span>')[0];
                        }
                    }
            });
});
`

我的php文件是json数据的样子:

[{"userid":"25","name":"Checkbnotif","dir":"201910","avatar":"","slug":"checkbnotif"}]

请告诉我它是如何工作的!我是新手,我尝试做点什么! 对不起我的英语

【问题讨论】:

    标签: summernote mention


    【解决方案1】:

    metions 是样本数据。

    所以搜索功能中的this.mentions 将不起作用。

    您可以重新定义搜索功能。

    search: function (keyword, callback) {
    
        $.ajax({
            url: baseURL + "thanh_vien/userjson/" + keyword,
            type: 'get',
            dataType: "json",   
            async: false
        }).done(function (items) {
            callback($.grep(items, function (item) {
                return item.slug.indexOf(keyword) == 0;
            }));
        });
    
    },
    

    【讨论】:

    • 感谢金浩!它工作完美,但我需要更多帮助,我希望用户在 @ 后输入至少 2 个字符来搜索要提及的成员!你能给我看看吗!谢谢
    猜你喜欢
    • 2018-03-07
    • 1970-01-01
    • 2018-05-07
    • 2020-01-12
    • 2016-07-27
    • 1970-01-01
    • 2020-02-07
    • 2016-03-12
    • 1970-01-01
    相关资源
    最近更新 更多