Backbone Boilerplate
Starting template for prototypes using Bootstrap and Backbone.
HTML
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
<script src="https://raw.github.com/janl/mustache.js/master/mustache.js"></script>
<script src="https://github.com/hongymagic/jQuery.serializeObject/raw/master/jQuery.serializeObject.js"></script>
<script src="http://documentcloud.github.com/backbone/examples/backbone-localstorage.js"></script>
<script id="template" type="template">
some content
</script>
JavaScript
Model = Backbone.Model.extend({})
data ={
tagName: 'li'
}
model = new Model(data)
View = Backbone.View.extend({
template: '#template',
tagName: function(){
return this.model.get('tagName');
},
render:function(){
this.template = _.template($(this.template).html()); this.$el.html(this.template(this.model.toJSON()));
return this;
}
})
view = new View({model: model})
console.log(view)
$(document.body).append(view.render().$el)