Last active
May 15, 2024 16:16
-
-
Save jharding/9458749 to your computer and use it in GitHub Desktop.
Example for http://twitter.github.io/typeahead.js/examples/.
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
<div id="bloodhound"> | |
<input class="typeahead" type="text" placeholder="States of USA"> | |
</div> |
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
// constructs the suggestion engine | |
var states = new Bloodhound({ | |
datumTokenizer: Bloodhound.tokenizers.whitespace, | |
queryTokenizer: Bloodhound.tokenizers.whitespace, | |
// `states` is an array of state names defined in "The Basics" | |
local: states | |
}); | |
$('#bloodhound .typeahead').typeahead({ | |
hint: true, | |
highlight: true, | |
minLength: 1 | |
}, | |
{ | |
name: 'states', | |
source: states | |
}); |
for the newbeies like me; to make bloodhound work standalone...
$(document).ready(function() {
/ / add states var here (search data)
var states = ['Alabama', 'Chicago',etc ]
// constructs the suggestion engine
var states = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
// states
is an array of state names defined in "The Basics"
local: states
});
$('#bloodhound .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: states
});
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Had the same issue. While debugging recognize that data was wrong cached.
window.localStorage.clear()
fixed the issue.
when it can't find data in cache it goes to fetch functionality and then it creates correct data structure.
Also be sure that
datumTokenizer
and
queryTokenizer
is initilized like a function, for example:
datumTokenizer: function (data) {
var wordToken = A.Bloodhound.tokenizers.whitespace(data.name);
return wordToken;
},
queryTokenizer: function (searchStr) {
return A.Bloodhound.tokenizers.nonword(searchStr);
},
where arguments:
data - it's row with column 'name'
searchStr - it's string which were typed by user in a control