Last active
January 1, 2016 21:59
-
-
Save j0lvera/8206847 to your computer and use it in GitHub Desktop.
Backbone.stickit Example
This file contains hidden or 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({}); | |
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