Skip to content

Instantly share code, notes, and snippets.

@daytonn
Created November 24, 2014 02:23
Show Gist options
  • Select an option

  • Save daytonn/ea59c9fb4480d683367b to your computer and use it in GitHub Desktop.

Select an option

Save daytonn/ea59c9fb4480d683367b to your computer and use it in GitHub Desktop.
JSKit autocomplete (naive)
/* 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