Skip to content

Instantly share code, notes, and snippets.

@seanoshea
Created December 7, 2011 22:47
Show Gist options
  • Save seanoshea/1445123 to your computer and use it in GitHub Desktop.
Save seanoshea/1445123 to your computer and use it in GitHub Desktop.
Simple Backbone Model/View
window.PhotoPageModel = Backbone.Model.extend({
defaults: function() {
return {
index: 0,
enabled: true,
active: false
};
},
setActive: function() {
}
});
window.PhotoPageView = Backbone.View.extend({
tagName: 'li',
template: _.template($('#photo-page-template').html()),
events: {
'click': 'onClick',
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
onClick: function(evt) {
evt.preventDefault();
$('a', $(this.el)).addClass('active');
this.model.setActive();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment