我想使用javascript typeahead bloodhound,但它与遥控器无法正常工作。
这是我的Javascript代码:
<script type="text/javascript">
jQuery(document).ready(function($) {
var clubs = new Bloodhound({
datumTokenizer: function () {
return Bloodhound.tokenizers.obj.whitespace;
},
queryTokenizer: function () {
return Bloodhound.tokenizers.whitespace;
},
remote: {
url: "{{ url('club/listall') }}"+'/%QUERY%',
filter: function(searchClubs) {
console.log(searchClubs);
return searchClubs;
},
wildcard: "%QUERY%"
},
});
$(".club-search").typeahead({
hint: true,
highlight: true,
minLength: 1
}, {
source: clubs.ttAdapter(),
name: 'clubsList',
templates: {
empty: [
'<div class="list-group search-results-dropdown"><div class="list-group-item">Aucun club trouvé.</div></div>'
],
header: [
'<div class="list-group search-results-dropdown">'
],
suggestion: function (data) {
return '<a href="{{ url('club') }}' + '/' + data.id + '" class="list-group-item"><span class="row">' +
'<span class="avatar">' +
'<img src="{{asset('/')}}' + blason + '">' +
"</span>" +
'<span class="name">' + data.name + '<br><small style="color:grey;">(Ligue ' + data.league_name + ')</small></span>' +
"</span>"
}
}
});
});
</script>
但是它没有完全正常工作......一般来说,它会找到结果,但我会给你一个搜索查询的例子。一个可能的问题是“montagnarde”。我会给你每封信的结果。打字:
m --> lot of results
mo --> lot of results
mon --> lot of results
mont --> lot of results
monta --> lot of results
montag --> lot of results
montagn --> lot of results
montagna --> no result
montagnar --> finds only "J.S. MONTAGNARDE"
montagnard --> finds only "J.S. MONTAGNARDE"
montagnarde --> finds only "J.S. MONTAGNARDE" and "LA MONTAGNARDE"
montagnarde i --> finds only "U.S. MONTAGNARDE INZINZAC"
而console.log(searchClubs)
给了我不同的结果。
有人看到问题在哪里吗?提前谢谢!
答案 0 :(得分:0)
我找到了解决方案。
我使用的是twitter / typeahead.js版本0.11.1,不幸的是这个版本不再被维护了。
我们必须使用:corejavascript / typeahead.js版本1.1.1