我非常絕望!TypeAhead不顯示查詢結果
我有Bootstrap Typeahead的這個問題。
HTML標記:
<div class="form-group">
<label for="">Recipients</label>
<input id="recipients" name="recipients"
autocomplete="off"
class="form-control"
data-role="tagsinput">
</div>
的JavaScript:
$('#recipientsContainer').tagsinput({
allowDuplicates: false,
trimValue: true,
confirmKeys: [13, 44],
typeahead: {
hint: true,
highlight: true,
minLength: 4,
limit: 10,
source: function (query) {
$.ajax({
url: "/app/route",
type: 'POST',
dataType: 'JSON',
data: {'query' : query},
success: function(data) {
console.log(data);
return(data);
}
});
},
afterSelect: function() {
this.$element[0].value = '';
}
}
});
Ajax調用後,我在consolle得到這個數組:
["Justin Demetria +393281893574", "Dylan Alea +393700488191", "Zahir Tatyana +393007841301", "Ryan Veda +393542236060", "Hunter Wanda +393393156943"]
問題是:我什麼都看不到(沒有出現。打字頭不起作用。
在控制檯中,我得到這個錯誤
bootstrap-tagsinput.js Uncaught TypeError: Cannot read property 'success' of undefined.
我怎樣才能解決呢?
我使用Bootstrap 3,最後一個Typeahead js源代碼。
我讀了所有你的代碼的成功,但我不明白我怎麼可以用它在我的typehead功能在tagsinput函數內使用(如我的代碼)..你能給我更多的幫助嗎?非常感謝.. –
您不必使用tagsinput函數,只需使用typeahead函數就像在我的代碼中看到的一樣,並指定其在api中記錄的行爲。 – 2016-08-03 13:13:17
如果我把你的代碼放在我的頁面中,例如,我收到這個錯誤:bloodhound沒有定義 –