Understanding nested views
A nested view or subview is basically a child view. The necessity of a subview arises when we have a complex view and we want to separate a part of it for the sake of simplicity, better event-handling, and a better model-view relationship.
To give you an example, assume that we have a collection of similar data and we need to display a list item for each type of data. In this case, it is always preferable to have separate views and models that give an option to control the behavior of the view attached to each model. When you click on an item, you may need to use the data for that item for further processing. If the item is a subview, we can get the data readily from the model attached to it. We will explain this concept in the example that follows.
We have seen UserItemView
in Chapter 1, Reducing Boilerplate with Plugin Development, which uses the User
model. Now, let's introduce a collection of user data that will be displayed as a list:
var User = Backbone.Model...