Switching a ListView Template Dynamically

You can assign a function to the ListView control’s itemTemplate property. This is great, because it means that you can switch the template used to render a ListView item at runtime.

Imagine, for example, that you want to display products using two templates: one template for normal products and one template for on-sale products (see Figure 8.18). The HTML page in Listing 8.17 includes the two templates.

Image

FIGURE 8.18 Switching templates dynamically

LISTING 8.17 Switching Templates Dynamically (dynamicTemplate\dynamicTemplate.js)

<div id="tmplProduct"    data-win-control ...

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.