Skip to content

Instantly share code, notes, and snippets.

@shohey1226
Created June 15, 2013 05:33
Show Gist options
  • Save shohey1226/5787042 to your computer and use it in GitHub Desktop.
Save shohey1226/5787042 to your computer and use it in GitHub Desktop.
app.views.HomeView = Backbone.View.extend({
initialize: function () {
this.searchResults = new app.models.EmployeeCollection();
this.searchresultsView = new app.views.EmployeeListView({model: this.searchResults});
},
render: function () {
this.$el.html(this.template());
$('.scroller', this.el).append(this.searchresultsView.render().el);
return this;
},
events: {
"keyup .search-key": "search",
"keypress .search-key": "onkeypress"
},
search: function (event) {
var key = $('.search-key').val();
this.searchResults.fetch({reset: true, data: {name: key}});
},
onkeypress: function (event) {
if (event.keyCode === 13) { // enter key pressed
event.preventDefault();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment