Created
September 11, 2012 12:17
-
-
Save sontek/3697998 to your computer and use it in GitHub Desktop.
Example of how to manage embedded views with Backbone.js
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
Layout = Backbone.View.extend({ | |
initialize: function() { | |
var me = this; | |
this.setViews(_.extend({}, this.views, this.options.views)); | |
if (this.options.template) { | |
this.template = this.options.template; | |
} | |
if (this.options.menu) { | |
this.menu = this.options.menu; | |
} | |
this.templateContext = _.extend({}, | |
this.templateContext, | |
this.options.templateContext | |
); | |
} | |
, setViews: function(views) { | |
this.views = _.extend({}, this.views, views); | |
} | |
, views: {} | |
, render: function() { | |
console.log(this.templateContext); | |
var t = Mustache.to_html($(this.template).html(), this.templateContext); | |
this.$el.html(t); | |
_.each(this.views, function(view, key) { | |
this.$el.find(key).html(view.render().el); | |
}, this); | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment