1
我是新手,在Typeahead和Bloodhound上工作,並且使用最新的js。以下是我的示例代碼。 HTML:多個數據集不能與Twitter一起工作Typeahead/Bloodhound
<div id="multiple-datasets">
<input class="typeahead" type="text" placeholder="NBA and NHL teams">
</div>
下面是腳本:
var nbaTeams = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: '{ "names": ["Aaron Kreisler","Adam Alder","Adam Preece"]}'
});
var nhlTeams = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: '{ "titles": ["Acute Chronic Pancreatitis Program", "Aerodigestive Program", "Analytical Imaging and Modeling Center (AIM)"]}'
});
$('#multiple-datasets .typeahead').typeahead({
highlight: true
},
{
name: 'nba-teams',
display: 'team',
source: nbaTeams,
templates: {
header: '<h3 class="league-name">NBA Teams</h3>'
}
},
{
name: 'nhl-teams',
display: 'team',
source: nhlTeams,
templates: {
header: '<h3 class="league-name">NHL Teams</h3>'
}
});
任何幫助。謝謝!