gpt4 book ai didi

javascript - 如何使用 typeahead.js 显示 "No Results Found"?

转载 作者:行者123 更新时间:2023-11-30 23:58:54 24 4
gpt4 key购买 nike

当用户输入没有建议时,我试图显示结果未找到消息。 typeahead.js 在向文本字段提供输入时显示输入建议。如果没有找到建议,那么如何显示未找到结果消息?...版本是 typeahead .js 0.11.1

最佳答案

您可以使用empty参数检查是否没有结果:

我对上面的代码进行了一些编辑,以便它可以帮助其他人搜索相同的内容。

$('.typeahead').typeahead({
hint: false,
highlight: true,
minLength: 3,
},
{
name: 'firstnames',
displayKey: 'value',
source: firstnames.ttAdapter(), // this is your result variable
templates: {
empty: function(context){
// console.log(1) // put here your code when result not found
$(".tt-dataset").text('No Results Found');
}
}

关于javascript - 如何使用 typeahead.js 显示 "No Results Found"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41594246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com