Created
February 9, 2017 09:49
-
-
Save nalgeon/cb484b7d9f4cf23fc2537c36e488fc1a to your computer and use it in GitHub Desktop.
Пример подключения подсказок DaData для typeahead.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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