Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// In our DOM ready
var poets = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit:10,
prefetch: {
// url points to a json file that contains an array of poet names
// e.g. ['Baudelaire', 'Beckett']
url: './poets.json',
filter: function(list){
return $.map(list, function(poet) { return { name: poet }; });
}
}
});
var philosophers = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit:10,
prefetch: {
// url points to a json file that contains an array of philosopher names
// e.g. ['Descartes', 'Derrida']
url: './philosophers.json',
filter: function(list){
return $.map(list, function(philosopher) { return { name: philosopher }; });
}
}
});
poets.initialize();
philosophers.initialize();
$('#multiple-datasets .typeahead').typeahead({
highlight: true
},
{
name: 'poets',
displayKey: 'name',
source: poets.ttAdapter(),
templates: {
header: '<h3 class="league-name">Poets</h3>'
}
},
{
name: 'philosophers',
displayKey: 'name',
source: philosophers.ttAdapter(),
templates: {
header: '<h3 class="league-name">Philosophers</h3>'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment