【发布时间】:2021-06-28 10:03:00
【问题描述】:
我已经使用 Bloodhound 实现了 Typeahead 以获取远程 JSON 数据,它可以工作,但是当我删除输入内容并键入其他内容时,会出现相同的结果。我在 chrome 开发工具中检查了网络,只有一个请求,即使我删除并再次开始输入,也没有新请求。我该如何解决? keyup 应该有新的请求了?
var articles = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '../fetch-article',
wildcard: '%QUERY'
}
});
$('#search-article .typeahead').typeahead(null, {
name: 'articles',
display: 'value',
highlight: true,
limit: Infinity,
minLength: 3,
source: articles,
templates: {
empty: [
'<div class="empty-message">',
'Article not found',
'</div>'
].join('\n'),
suggestion: function(data) {
return '<div class="tt-suggest-page">' + data.title + '<br><a href="../copyright/' + data.slug + '">Read More</a></div>';
}
}
});
【问题讨论】:
标签: typeahead.js