Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Пример подключения подсказок DaData для typeahead.js
var address = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote :{
url: 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address/',
replace: function(url,q){
this.ajax.data = '{ "query": "' + q + '" }';
return url + '?q=' + q;
},
filter: function(resp){
return resp.suggestions;
},
ajax: {
type: 'POST',
dataType: 'json',
headers: {
'Authorization': 'Token REPLACE_WITH_API_KEY',
'Content-Type': 'application/json'
}
}
}
});
address.initialize();
$('#remote .typeahead').typeahead(null, {
name: 'address',
displayKey: 'value',
source: address.ttAdapter()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment