Backbone as primary UI front end developer framework. This articles demonstrates how to add child components/childViews to your backbone views.
Before starting, let’s think about what do we need to create childViews. (Requirements)
- When a parent view is rendered, all of its childViews should be re-rendered
- When a parent view is destroyed, all of its childViews should be destroyed
- A parent view should have capability to list down all of its childViews and call render on them
Step1: (Override Backbone.View.Prototype.close function – One time step)
Step2: Define an
onBeforeRender function in the parentView which has childViews (BaseIndexView.js has this)
Step3: In ParentView define childViews and render each childView (RuleIndexView.js)
There are two baseViews in the code base right now.
- BaseIndexView – For IndexViews based on collection
- BaseView – For Model based views
All other views extend either of these or subsidiary of these views.