Skip to content

Instantly share code, notes, and snippets.

@andreisebastianc
Created July 6, 2014 19:57
Show Gist options
  • Save andreisebastianc/53f7a62a7bc9b6c46ea3 to your computer and use it in GitHub Desktop.
Save andreisebastianc/53f7a62a7bc9b6c46ea3 to your computer and use it in GitHub Desktop.
Poor man backbone layout manager
_.extend(Backbone.View.prototype, {
serialize: function () {},
beforeRender: function () {},
afterRender: function () {},
render: function (where) {
var tmp, that;
this.beforeRender();
// @note assume template always set with tpl property
// @note assignment
if ( !( tmp = window.app.templates[this.tpl] ) ){
that = this;
$.ajax({
url: 'src/app/templates/'+this.tpl,
async: false
}).done(function (res) {
tmp = res;
window.app.templates[that.tpl] = res;
});
}
this.el.innerHTML = _.template(tmp, this.serialize() )();
where.appendChild(this.el);
this.afterRender();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment