我正在使用Twitter類型,但發現很難從mysql查詢中劃分結果。輸入提前血獵犬排序返回值。
我的JSON輸出看起來是這樣的:{「ID」:「1」,「名」:「布拉沃」}在當前狀態下
在預輸入結果顯示的名稱和ID,我會喜歡能夠僅顯示名稱,但輸入的實際提交值是id。我的腳本是流動的:
<script type="text/javascript">
// Instantiate the Bloodhound suggestion engine
var suggestions = new Bloodhound({
datumTokenizer: function (datum) {
return Bloodhound.tokenizers.whitespace(datum.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'includes/livesearch.php?key=%QUERY',
wildcard: '%QUERY',
filter: function (name) {
// Map the remote source JSON array to a JavaScript object array
return $.map(name, function (name) {
return {
value: name
};
});
}
}
});
// Initialize the Bloodhound suggestion engine
suggestions.initialize();
// Instantiate the Typeahead UI
$('.typeahead').typeahead({
hint: true,
minLength: 2
}, {
limit: 7,
displayKey: 'value',
source: suggestions.ttAdapter(),
});
</script>
我非常歡迎任何幫助或建議。
謝謝!
作品完全相同的方式我所需要的!非常感謝你 ! –