Reputation: 384
I'm using typeahead.js with both prefetch and remote http://twitter.github.io/typeahead.js/examples/#custom-templates
$(document).ready(function() {
var castDirectors = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: '../api/v1/search/people_typeahead',
remote: '../api/v1/search/people_typeahead?q=%QUERY'
});
castDirectors.initialize();
$('#remote .typeahead').typeahead(null, {
name: 'cast-directors',
displayKey: 'value',
source: castDirectors.ttAdapter(),
templates: {
empty: [
'<div class="empty-message">',
'no matching names',
'</div>'
].join('\n'),
suggestion: Handlebars.compile('<p><a href="{{link}}">{{value}}</a></p>')
}
});
});
However, there are duplicated entries in the prefetch JSON and remote JSON. How can I dedup so that it only shows one entry?
Upvotes: 3
Views: 1578
Reputation: 20230
Add the dupDector option to your Bloodhound intitialisation code i.e. put the following code after "remote:" :
dupDetector: function(remoteMatch, localMatch) {
return remoteMatch.value === localMatch.value;
}
You haven't included your JSON so I cannot be sure that the comparison being made in the code above is correct. This code will ignore duplicate values in the local and remote datasources.
Upvotes: 4