0
你好,我正在尝试在数据库上进行搜索,并在用户使用typeahead键入时提供自动建议。数据正在以用户键入的形式返回,但自动建议并未显示在输入字段下。Twitter Typeahead不显示建议
$(window).load(function(){
// Instantiate the Bloodhound suggestion engine
var employees = new Bloodhound({
datumTokenizer: function (datum) {
return Bloodhound.tokenizers.whitespace(datum.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'https://www.example.com/prs/emp.php?query=%QUERY',
wildcard: '%QUERY',
filter: function (employees) {
return $.map(employees.results, function (employee) {
return {
label: employee.label,
value: employee.value
};
});
}
}
});
// Initialize the Bloodhound suggestion engine
employees.initialize();
// Instantiate the Typeahead UI
$('.typeahead').typeahead(null, {
displayKey: 'value',
source: employees.ttAdapter(),
templates: {
suggestion: function(data){
return '<p>Name: <strong>' + employee.label + '</strong> | ID: ' + employee.value + '</p>';}
}
});
<input type="text" autocomplete="off" spellcheck="false" class="typeahead employeeName form-control" name="employeeName" style="margin:0px auto;overflow:visible;" id="employeeName" placeholder="Employee Name">
我正在从PHP文件 [{"label":"Austin, Pickering","value":"155"}]
如下回应,我不知道为什么它不会显示数据。我花了数小时试图弄清楚。任何帮助,将不胜感激。
嗨感谢您的期待。代码片段不会在此处运行,因为远程查询数据库时我已将url更改为示例url。 – AKAust