[英]Bootstrap 4 Typeahead
我正在使用jQuery Bootstrap Typeahead 。 我從我的文件中獲取數據但是沒有填充/顯示typeahead下拉列表。
這是我的JS:
(function() {
"use strict";
var $input = $('.typeahead');
$('.typeahead').typeahead({
source: function (query, process) {
return $.getJSON(
'url-to-file.php',
{ query: query },
function (data) {
console.log(data)
return process(data);
})
}
});
})();
console.log()
返回一個(正確的)JSON數組:
[ "item1", "item2", ... ]
但我不知道該怎么辦。 謝謝你的幫助
數據源應該是......
[{name:"item1","id":"1"},{name:"item2","id":"2"},etc..]
然后在這樣的輸入上使用data-provide
......
<div class="input-group">
<input type="text" data-provide="typeahead" class="form-control typeahead border-primary" name="query" id="query" placeholder="search..." autocomplete="off">
</div>
編輯:您還可以使用簡單的字符串數組 : https : //www.codeply.com/go/knBpcbhlFE
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.