Rebar.CompositeView Class
Most of the time Backbone views need to be able to contain other views. When you do this you run into situations where you need to add the view then render and when you go to destroy the parent view, you want to make sure you properly dispose of its children. The composite view makes managing child parent relationships a bit easier by adding recursive destroy functionality as well as making it possible to quickly add and remove child views.
Constructor
Rebar.CompositeView
()
Example:
var composite = new Backbone.Rebar.CompositeView({
...
});
var view = new Backbone.Rebar.View({
...
});
composite.addSubView(view);
Item Index
Methods
addSubView
-
view
Adds a sub view to a container BaseView
Parameters:
-
view
View
addSubViews
-
views
Adds an array of sub views to a container BaseView
Parameters:
-
views
ArrayArray of subviews
destroy
()
This method is a great helper method to call when the subclass view is about to be removed. It recursively will call destroy on any subviews reference in the sub views array. It also handles removing any event listeners that may have been added to the subViews array.
destroySubView
-
view
Checks to see if the passed view has destroy functionality and then if it does not calls the prototype destroy functionality and passes the reference
Parameters:
-
view
View
removeAllSubViews
()
Removes all sub views from view
removeSubView
-
view
Removes a sub view from the container view
Parameters:
-
view
ObjectA base view or a cid of the sub view