Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created October 14, 2010 15:49
Show Gist options
  • Save jashkenas/626425 to your computer and use it in GitHub Desktop.
Save jashkenas/626425 to your computer and use it in GitHub Desktop.
var Product = Backbone.Model.extend({
fromStoreName: function() { return 'Crate & Barrel'; }
});
var glassJar = new Product({ storesUrl: 'http://www.crateandbarrel.com' });
var products = new Backbone.Collection;
products.add([glassJar]);
var ProductView = Backbone.View.extend({
tagName: 'div'
, className: 'product'
, events: { 'submit' : 'loadMessage' }
, loadMessage: function(){ alert(this.model.get('storesUrl')); }
, template: function(data){
var compiled = _.template("store: <%= storesUrl %>")
return compiled(data);
}
, render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});
var view = new ProductView({
model: glassJar,
});
$(document).ready(function() {
$(".product").html(view.template(glassJar.toJSON()));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment