Skip to content

Instantly share code, notes, and snippets.

@jharding
Last active December 20, 2015 04:08
Show Gist options
  • Save jharding/6068247 to your computer and use it in GitHub Desktop.
Save jharding/6068247 to your computer and use it in GitHub Desktop.
I'm trying to work out the new typeahead.js API for v0.10 and I'm looking for some feedback. The issue is that due to the amount of flexibility added in v0.10, designing a clean, intuitive API is proving to be a challenge. This gist contains 2 possible APIs I've been kicking around. I'm not really a big fan of either of them so if you have any i…
// simple
// ------
$('.typeahead').typeahead({
autoselect: true,
hightlight: true,
hint: true
}).typeahead('add', {
name: 'films',
source: {
remote: '/films?q=%QUERY'
},
templates: {
suggestion: suggestionTemplate
}
});
// complex
// -------
$('.typeahead').typeahead({
autoselect: true,
hightlight: true,
hint: true
}).typeahead('add', {
name: 'presidents',
source: {
local: ['George Washington', 'John Adams'],
remote: '/presidents?q=%QUERY'
},
templates: {
suggestion: suggestionTemplate,
empty: emptyTemplate
}
},
{
name: 'basketball-players',
source: {
local: ['Ben Wallace', 'Rasheed Wallace'],
remote: '/bball?q=%QUERY'
},
templates: {
suggestion: suggestionTemplate,
empty: emptyTemplate
}
});
// simple
// ------
$('.typeahead').typeahead({
autoselect: true,
hightlight: true,
hint: true
sections: {
name: 'films',
source: {
remote: '/films?q=%QUERY'
},
templates: {
suggestion: suggestionTemplate
}
}
});
// complex
// -------
$('.typeahead').typeahead({
autoselect: true,
hightlight: true,
hint: true,
sections: [
{
name: 'presidents',
source: {
local: ['George Washington', 'John Adams'],
remote: '/presidents?q=%QUERY'
},
templates: {
suggestion: suggestionTemplate,
empty: emptyTemplate
}
},
{
name: 'basketball-players',
source: {
local: ['Ben Wallace', 'Rasheed Wallace'],
remote: '/bball?q=%QUERY'
},
templates: {
suggestion: suggestionTemplate,
empty: emptyTemplate
}
}
]
});
@nagarajanprince
Copy link

can you send how do typehead.js full code .
index.html
file name.json
and *.js file

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