Created
March 8, 2014 18:05
-
-
Save mildfuzz/9436132 to your computer and use it in GitHub Desktop.
Assign Several Subviews to selectors within current view
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
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