usercode
usercode

Reputation: 309

search and typeahead in JavaScript

In the following JSFiddle Code, The list of location is parsed from the jSON object and shown. I would like to add a search and a type ahead functionality to it. The following code is not working.

var sourceArr = [];
for (x in data.sessions) {
    sourceArr.push(data.sessions[x].ID);
}

$(".search").typeahead({
    source: sourceArr
});

$(".search").keyup(function () {
    var userInput = $(this).val();
    $(".findsession-list li").map(function (index, value) {
        $(value).toggle($(value).text().toLowerCase().indexOf(userInput) >= 0);
    });
});

Upvotes: 1

Views: 714

Answers (1)

Hieu Nguyen
Hieu Nguyen

Reputation: 8623

Not sure what do you expect from typeahead but you should use local instead of source:

$(".search").typeahead({
    local: sourceArr
});

Fiddle: http://jsfiddle.net/hieuh25/WsnDP/22/

Upvotes: 2

Related Questions