Skip to content

Instantly share code, notes, and snippets.

@redox
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redox/10434904 to your computer and use it in GitHub Desktop.
Save redox/10434904 to your computer and use it in GitHub Desktop.
How to redefine ttAdapter()
var index = client.initIndex('YourIndexName');
$('input#user_email').typeahead(null, {
// source is a function that takes the query and the typeahead.js callback function as parameters
source: function(query, cb) {
// perform the search
index.search(query, function(success, content) {
if (success) {
// at least one hit ?
if (content.hits.length > 0) {
firstHit = content.hits[0];
}
// call the regular callback to inform typeahead about the results
cb(content.hits);
}
}, { hitsPerPage: 5 }); // force 5 hits only?
},
name: 'users',
displayKey: 'email',
templates: {
suggestion: function(hit) {
return template.render(hit);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment