var search = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: data
});
$('#search').typeahead('destroy');
search.clearPrefetchCache();
$('#search').typeahead(null, {
name: 'search',
displayKey: 'name',
source: search,
templates: {
empty: function(context) {
// console.log(1) // put here your code when result not found
$(".tt-dataset").text('No Results Found');
//console.log('no result')
}
}
})
.bind('typeahead:select', function(ev, type) {
$('#type').val(type.type);
var input = document.getElementById("search");
input.addEventListener("keyup", function(event) {
// Cancel the default action, if needed
event.preventDefault();
if (event.keyCode === 13) {
document.getElementById("search-button").click();
}
});
});
}
});
我正在尝试添加带有建议的标题。标头是动态的。 请帮助在我的搜索建议中添加标题。 my typeahead suggestion
header like this 像这样的示例添加标题