Add the Search Result List Item View
To define the search result list item view, you design and implement the view of a single row in a list. Each list item displays the following user fields:
- SmallPhotoUrl
- FirstName
- LastName
- Title
-
Immediately after the
UserListViewview definition, create the view for the search result list item. Once again, extendBackbone.Viewand indicate that this view is a list item by defining thetagNamemember. For the remainder of this procedure, add all code in theextend({})block. -
Add an
<li>tag. -
Load the template by calling
_.template()with the raw content of theuser-list-itemscript. -
Add a
render()function. Thetemplate()function, fromunderscore.js, takes JSON data and returns HTML crafted from the associated template. In this case, the function extracts the customer’s data from JSON and returns HTML that conforms to theuser-list-itemtemplate. During the conversion to HTML, thetemplate()function replaces free variables in the template with corresponding properties from the JSON data. -
Add a
close()method to be called from the list view that does necessary cleanup and stops memory leaks.
Here’s the complete extension.