Created
July 6, 2014 19:57
-
-
Save andreisebastianc/53f7a62a7bc9b6c46ea3 to your computer and use it in GitHub Desktop.
Poor man backbone layout manager
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
_.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