Created
April 25, 2015 10:23
-
-
Save jharding/ee0e44e70097c211070d to your computer and use it in GitHub Desktop.
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="default-suggestions"> | |
<input class="typeahead" type="text" placeholder="NFL Teams"> | |
</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
var nflTeams = new Bloodhound({ | |
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'), | |
queryTokenizer: Bloodhound.tokenizers.whitespace, | |
identify: function(obj) { return obj.team; }, | |
prefetch: '../data/nfl.json' | |
}); | |
function nflTeamsWithDefaults(q, sync) { | |
if (q === '') { | |
sync(nflTeams.get('Detroit Lions', 'Green Bay Packers', 'Chicago Bears')); | |
} | |
else { | |
nflTeams.search(q, sync); | |
} | |
} | |
$('#default-suggestions .typeahead').typeahead({ | |
minLength: 0, | |
highlight: true | |
}, | |
{ | |
name: 'nfl-teams', | |
display: 'team', | |
source: nflTeamsWithDefaults | |
}); |
let suggestion_source = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: [
'Red','Blood Red','White','Blue','Yellow','Green','Black','Pink','Orange'
],
remote: {
url: "/query?key=%QUERY",
wildcard: "%QUERY",
transform: function (response) {
return response;
}
}
});
# async args not null
function nflTeamsWithDefaults(q, sync, async) {
if (q === '') {
sync(suggestion_source.local);
} else {
suggestion_source.search(q, sync, async);
}
}
$(`#the-basics${id} .typeahead`).typeahead(
{highlight: true, minLength: 0},
{source: nflTeamsWithDefaults}
);
let suggestion_source = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: [
'Red','Blood Red','White','Blue','Yellow','Green','Black','Pink','Orange'
],
remote: {
url: "/query?key=%QUERY",
wildcard: "%QUERY",
transform: function (response) {
return response;
}
}
});
# async args not null
function nflTeamsWithDefaults(q, sync, async) {
if (q === '') {
sync(suggestion_source.local);
} else {
suggestion_source.search(q, sync, async);
}
}
$('#the-basics .typeahead').typeahead(
{highlight: true, minLength: 0},
{source: nflTeamsWithDefaults}
);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这是一个错误的例子,this is error code