dimanche 3 juillet 2016

Dynamic String[] for twitter typeahead

I am doing an ajax call to return a list of objects. Once the object array is populated, a separate string[] is populated with the Objects' names. I would like to pass this to twitter typeahead using a Bloodhound source.

-So far I can see the bloodhound gets populated with all the strings but the twitter hint isn't working properly.

Bloodhound -

var clientList = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: [Clients.entitiesNames]});
clientList.initialize();

Typeahead - initialized after

$('#search-box).typeahead({
            hint: true,
            highlight: true,
            minLength: 1
        },
        {
            name: 'name',
            source: clientList
        }
    );

Like I said, I know that the bloodhound gets populated with the correct number of indices in the array but the twitter hint doesn't appear. I'm using bootstrap 3. I also have the ajax to render the Object[] in a init() that's called on page load in js. Once the ajax finishes, the init() for the twitter typeahead is called.

I thank you for helping in advance.

Aucun commentaire:

Enregistrer un commentaire