我在我的网站中添加了 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> </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> </b></span>')[0];
}
}
});
});
`
我的 php 文件是 json 数据,如下所示:
[{"userid":"25","name":"Checkbnotif","dir":"201910","avatar":"","slug":"checkbnotif"}]
请告诉我它是如何工作的!我是新手,我尝试做点什么!对不起我的英语