Skip to content

Instantly share code, notes, and snippets.

@nalgeon
Created February 9, 2017 09:49
Show Gist options
  • Save nalgeon/cb484b7d9f4cf23fc2537c36e488fc1a to your computer and use it in GitHub Desktop.
Save nalgeon/cb484b7d9f4cf23fc2537c36e488fc1a to your computer and use it in GitHub Desktop.
Пример подключения подсказок 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