Created
October 14, 2010 15:49
-
-
Save jashkenas/626425 to your computer and use it in GitHub Desktop.
This file contains 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
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