jquerytwitter-bootstrapbootstrap-typeahead

bootstrap typeahead - changing source


I looking for a way to change source for typeahed.

For instance, assume I have the following 2 lists, and depend on the case, I'd like to have the typeahead workingin with a different source.

var list1 = ["this", "is", "first", "list"],
    list2 = ["second", "list", "comes", "here"];

$("selector").typeahead({source: list1})

Then, when I do

$("selector").typeahead({source: list2})

and start typing into the input box, the first list appears underneath the new one.

I tried doing

$("selector")
    .removeData()
    .typeahead({source: list2})

Yet, it has no effect.


Solution

  • You have to update the data field associated as indicated here :

    $("selector").data('typeahead').source = list2;