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.
-
In the
<script>
block that contains theSearchPage
view, extendBackbone.View
to show a list of search view results. Add an array for list item views and aninitialize()
function.For the remainder of this procedure, add all code to the
extend({})
block. -
Create the
render()
function. This function cleans up any existing list item views by callingclose()
on each one. -
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 defineapp.views.UserListItemView
later. -
Still in the
render()
function, append each list item view to the root DOM element and then return the renderedUserListView
object.
Here’s the complete extension: