Add the Search Result List View

The view for the search result list doesn’t need a template. It is simply a container for list item views. It tracks these views in the listItemViews member. If the underlying collection changes, it re-renders itself.

  1. In the <script> block that contains the SearchPage view, extend Backbone.View to show a list of search view results. Add an array for list item views and an initialize() function.

    For the remainder of this procedure, add all code to the extend({}) block.

  2. Create therender() function. This function cleans up any existing list item views by calling close() on each one.

  3. Still in the render() function, create a set of list item views for the records in the underlying collection. Each of these views is just an entry in the list. You define app.views.UserListItemView later.

  4. Still in the render() function, append each list item view to the root DOM element and then return the rendered UserListView object.

Here’s the complete extension: