【发布时间】:2023-04-06 09:46:02
【问题描述】:
我正在努力从Summernote Hints 的数据库中获取实时用户列表,但是在使用异步时它会崩溃,但是在关闭异步时会导致 UI 冻结...显然不是 UX 的最佳选择。
$(document).ready(function()
{
$('.editor').summernote({
height: 300,
hint: {
match: /\B@(\w*)$/,
users: function(keyword) {
var result = data;
$.ajax({
url: '/users/' + keyword,
type: 'get',
async: false //This works but freezes the UI
}).done(function(data)
{
result = data; //Set the result to the returned json array
});
return result;
},
search: function (keyword, callback) {
callback(this.users(keyword)); //callback must be an array
},
content: function (item) {
return '@' + item;
}
}
});
});
我怎样才能让异步工作而不摔倒?我相信这与承诺有关,但不确定。
【问题讨论】:
标签: javascript jquery ajax summernote