Skip to content

Instantly share code, notes, and snippets.

@chengscott
Last active October 10, 2015 10:15
Show Gist options
  • Select an option

  • Save chengscott/3d6ec682089a4912d8f6 to your computer and use it in GitHub Desktop.

Select an option

Save chengscott/3d6ec682089a4912d8f6 to your computer and use it in GitHub Desktop.
Twitter typeahead dynamic source from Parse.com
var ShopData = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'https://api.parse.com/1/classes/Shop?where={"name":{"$regex":"%QUERY"}}&limit=20',
wildcard: '%QUERY',
prepare: function (query, settings) {
// settings.type (method for jQuery 1.9+) default is GET
settings.dataType = 'json';
settings.contentType = "application/json; charset=UTF-8";
settings.headers = {
'X-Parse-Application-Id': 'YourIdHere',
'X-Parse-REST-API-Key': 'YourKeyHere'
};
settings.url = settings.url.replace('%QUERY', query);
return settings;
},
transform: function (response) { return response.results; }
}
});
$('.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
}, {
name: 'Shops',
display: 'name',
source: ShopData
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment