Created
December 2, 2012 16:20
-
-
Save k33g/4189559 to your computer and use it in GitHub Desktop.
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
var MustacheView = Backbone.View.extend({ | |
initialize : function (data) { | |
if(this.template) this.mustacheTemplate = this.template.html(); | |
this.data = data!==undefined ? data : []; | |
}, | |
render : function () { | |
var view = this; | |
var _render = function() { | |
if(view.data.toJSON == undefined) { | |
view.renderedContent = Mustache.to_html(view.mustacheTemplate, {data:view.data}); | |
} else { | |
view.renderedContent = Mustache.to_html(view.mustacheTemplate, {data:view.data.toJSON()}); | |
} | |
view.$el.html(view.renderedContent); | |
} | |
if(this.extTemplate && this.mustacheTemplate==undefined){ | |
$.ajax({ | |
type:"GET", | |
url:view.extTemplate, | |
error:function(err){ throw err; }, | |
success:function(template) { | |
view.mustacheTemplate = template; | |
_render(); | |
} | |
}); | |
} else { | |
_render(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment