Skip to content

Instantly share code, notes, and snippets.

@mrchief
Forked from jharding/bloodhound.html
Last active March 17, 2017 17:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrchief/da310b89a272b9628395 to your computer and use it in GitHub Desktop.
Save mrchief/da310b89a272b9628395 to your computer and use it in GitHub Desktop.
<div id="bloodhound">
<input class="typeahead" type="text" placeholder="States of USA">
</div>
// constructs the suggestion engine
var engine = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
// `states` is an array of state names defined in "The Basics"
local: $.map(states, function(state) { return { value: state }; })
});
// kicks off the loading/processing of `local` and `prefetch`
engine.initialize();
$('#bloodhound .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
displayKey: 'value',
// `ttAdapter` wraps the suggestion engine in an adapter that
// is compatible with the typeahead jQuery plugin
source: engine.ttAdapter()
});
@lii2
Copy link

lii2 commented Nov 18, 2016

Can you give a link to the json this code is referencing?

@karanjamwal
Copy link

I am assuming the states array will be like as :

var states = [ "Ohio", "New York", "Florida"];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment