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