Created
November 2, 2013 17:08
-
-
Save wheaties/7281152 to your computer and use it in GitHub Desktop.
Handlebars Defered Template w/ Backbone example use case
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
//Assumes jQuery, produces a lazy load template function. | |
var Template = function(el){ | |
var $el = $(el), | |
template = undefined; | |
//Compile template and store once. | |
return function(args){ | |
if(!template){ | |
template = Handlebars.compile($el.html()); | |
} | |
return template(args); | |
} | |
} |
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
//Defered Backbone View | |
var DeferedModelView = Backbone.View.extend({ | |
model: Backbone.Model, | |
template: function(){ | |
return '<div></div>' | |
}, | |
render: function(){ | |
var html = this.template(this.model.toJSON()); | |
this.$el.html(html); | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment