O'Reilly logo

Instant typeahead.js by Toby Osbourn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Collecting datasets (Become an expert)

So far we have looked at loading a dataset from several sources, but one really powerful aspect of typeahead.js is the ability to draw from several datasets at the same time. In this recipe, we will combine datasets in order to make a searchable list of some of my favorite comic book characters.

Getting ready

We can go back to using the index.html file as per our last recipe as we just need one input field here, and we will edit our custom.js file to pull from three local sources.

How to do it...

We will edit the custom.js file to look like this:

$(document).ready(function() { var xmen = ['Wolverine', 'Rouge', 'Beast']; var avengers = ['Hulk', 'Thor', 'The Black Widow']; var other = ['Deadpool', 'The Punisher'] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required