-
-
Save mrchief/da310b89a272b9628395 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<div id="bloodhound"> | |
<input class="typeahead" type="text" placeholder="States of USA"> | |
</div> |
This file contains hidden or 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
// 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() | |
}); |
I am assuming the states array will be like as :
var states = [ "Ohio", "New York", "Florida"];
Thanks for this man, i had to fix old code and this help alot.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you give a link to the json this code is referencing?