Created
April 13, 2012 14:40
-
-
Save davetheninja/2377348 to your computer and use it in GitHub Desktop.
Display Models for Backbone/Underscore template
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
window.MyView = Backbone.View.extend({ | |
... | |
render: function() { | |
var html = My.Namespace.Templates.apply("template_name", new MyDisplayModel({ | |
model: this.model, | |
assHatOfTheWeek: "asshatting on alcohol at confs" | |
})); | |
this.$el.html(html); | |
... | |
return this; | |
} | |
}); | |
window.MyDisplayModel = new JS.Class("MyDisplayModel", { | |
initialize: function(args) { | |
this.model = args.model; | |
this.someOtherThing = args.someOtherThing; | |
}, | |
ultimateAsshatPoints: function() { | |
return this.assHatOfTheWeek == "asshatting on alcohol at confs"; | |
}, | |
fullName: function() { | |
return this.model.get("first_name") + " " + this.model.get("last_name"); | |
} | |
}) | |
// template | |
<h1>Something</h1> | |
<% if (this.ultimateAsshatPoints()) { %> | |
<p>WE HAVE OUR WEENER! and his name is <% this.fullName() %></p> | |
<% } %> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment