Summernote从php中获得很多价值的提及

问题描述 投票:1回答:1

我将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个回答
0
投票

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

},
© www.soinside.com 2019 - 2024. All rights reserved.