API Docs for: 1.0.0
Show:

Rebar.CompositeView Class

Extends View

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);

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 Array

    Array 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
)
private

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 Object

    A base view or a cid of the sub view