Skip to content

Instantly share code, notes, and snippets.

@j0lvera
Last active January 1, 2016 21:59
Show Gist options
  • Save j0lvera/8206847 to your computer and use it in GitHub Desktop.
Save j0lvera/8206847 to your computer and use it in GitHub Desktop.
Backbone.stickit Example
var Product = Backbone.Model.extend({});
var ProductView = Backbone.View.extend({
template: _.template("<h1 id='name'></h1><p id='price'></p>"),
bindings: {
"#name": { modelAttr: "name" },
"#price": { modelAttr: "price", format: 'formatPrice' }
},
render: function() {
this.el.innerHTML = this.template();
this.stickit();
return this;
},
formatPrice: function(price) {
return "$" + price.toFixed(2);
}
});
var product = new Product({ name: "Camera", price: "$500" });
var productView = new ProductView({ model: product });
$("#main").append(productView.render().el);
// try on the console to change an attribute and
// the view will update automatically, e.g.
// product.set({ name: "Computer" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment