Skip to content

Instantly share code, notes, and snippets.

@mildfuzz
Created March 8, 2014 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildfuzz/9436132 to your computer and use it in GitHub Desktop.
Save mildfuzz/9436132 to your computer and use it in GitHub Desktop.
Assign Several Subviews to selectors within current view
Backbone.View.prototype.assign = function(set, preventEmpty) {
/*
accepts an object of selectors:arrays of views
maps each of the views to the selector
*/
var self = this;
//store all subviews
self.assignments = _.extend(self.assignments||{},set);
//
_.each(set, function(views, selector) {
if(!views) return;
if(!preventEmpty) {
var el = self.$(selector).empty();
} else {
var el = self.$(selector);
}
if(views instanceof Array != true) {
views = [views];
}
_.each(views, function(view) {
view.setElement(el).render();
});
}, this);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment