Created
November 27, 2014 06:39
-
-
Save arbinish/f181b37bef294979a5ec to your computer and use it in GitHub Desktop.
Bootstrap typeahead example. Handling a list of objects from API endpoint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
('input[type="text"]').typeahead | |
minLength: 3 | |
quietMillis: 250 | |
source: (query, process) -> | |
@options.map = {} | |
suggest = [] | |
self = @ | |
$.getJSON "api/users", {q: query}, (data) => | |
$.each data, (idx, item) -> | |
ele = "#{item.fullname} (#{item.name})" | |
self.options.map[ele] = item | |
suggest.push(ele) | |
process(suggest) | |
updater: (item) -> | |
return @options.map[item].name | |
# Sample resonpse from api/users | |
# [{name: "peter", fullname: "Peter Parker"}, {name: "bruce", fullname: "Bruce Wayne"}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment