Created
November 24, 2014 02:23
-
-
Save daytonn/ea59c9fb4480d683367b to your computer and use it in GitHub Desktop.
JSKit autocomplete (naive)
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
| /* jshint esnext: true */ | |
| var _ = require("lodash"); | |
| App.createController("Friends", { | |
| actions: ["index"], | |
| all: function() { | |
| this.cacheElements(); | |
| this.registerEvents(); | |
| }, | |
| index: function() { | |
| }, | |
| cacheElements: function() { | |
| this.$completionList = $("#completion-list"); | |
| this.$friendSearchBox = $("#query"); | |
| }, | |
| populateCompletionList: function(responseJSON) { | |
| this.$completionList.empty(); | |
| _.each(responseJSON.users, function(user) { | |
| this.$completionList.append("<li>" + user.firstname + " " + user.lastname + "</li>"); | |
| }, this); | |
| }, | |
| fetchCompletionList: function() { | |
| $.ajax({ | |
| url: "users/search", | |
| data: { query: this.$friendSearchBox.val() }, | |
| dataType: "json" | |
| }) | |
| .done(this.populateCompletionList); | |
| }, | |
| registerEvents: function() { | |
| this.$friendSearchBox.on("keyup", this.fetchCompletionList); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment