我已经配置了像这样的Twitter typeahead.js:
var filteredSource = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '@Url.Action("Get", "Search")/',
prepare: function (query, settings) {
settings.url = settings.url + $('#filter-select').val() + '?q=' + encodeURIComponent(query);
return settings;
},
rateLimitBy: 'throttle',
rateLimitWait: 800
}
});
$('#search').typeahead({
hint: false,
highlight: true,
minLength: 3
}, {
name: 'filtered-source',
display: 'value',
limit: 50,
source: filteredSource,
templates: {
empty: [
'<div>',
' Unable to find any results.',
'</div>'
].join('\n'),
suggestion: Handlebars.compile(templateData)
}
});
当用户进行搜索并开始输入类似于"key"的内容并暂停时,Bloodhound会向服务器发送一个搜索请求。当用户添加更多字母到输入框后,例如"keyword",另一个搜索将被发送到服务器。
但是,挂起的请求"key"首先需要等待浏览器完成,然后服务器才处理第二个请求,并且仅在完成后才显示结果。因此,在用户看到任何结果之前可能需要很长时间。
是否有一种方法可以通过Bloodhound取消挂起的请求,当关键字被更改时?