23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The header template in html/scenario1.html is very simple (and the item template is like what we’ve<br />

already seen):<br />

<br />

<br />

<br />

<br />

<br />

This is referenced in the control declaration (other options omitted):<br />

<br />

<br />

For the data sources, you can see that we’re now using a variable called myGroupedList with a<br />

property inside it called groups. What’s all this about?<br />

Well, let’s take a short conceptual detour. Although computers have no problem chewing on a<br />

bunch of raw data like the myList array, human beings like to view data with a little more organization.<br />

The three primary ways of doing this are grouping, sorting, and filtering. Grouping organizes items into<br />

groups, as shown in Figure 5-3; sorting orders items according to various rules; and filtering provides a<br />

subset of items that match certain criteria. In all three cases, however, you don’t want such operations to<br />

actually change the underlying data: a user might want to group, sort, or filter the same data in different<br />

ways from moment to moment.<br />

Grouping, sorting, and filtering, then, are thus referred to as projections of the data: they’re all<br />

connected to the same underlying data such that a change to an item in the projection will be<br />

propagated back to the source, just as changes in the source are reflected in the projection.<br />

The WinJS.Binding.List object provides methods to create these projections: createGrouped,<br />

createSorted, and createFiltered. Each method produces a special form of a WinJS.Binding.List:<br />

GroupedSortedListProjection, SortedListProjection, and FilteredListProjection, respectively. That<br />

is, each projection is a bindable list in itself, with a few extra methods and properties that are specific to<br />

the projection. You can even create a projection from a projection. For instance,<br />

createGrouped(...).createFiltered(...) will create a filtered projection on top of a grouped<br />

projection. (Note, however, that the list’s sort method does not create a projection. It applies the<br />

sorting in-place, just like the JavaScript array’s sort.)<br />

Now that we know about projections, we can see how myGroupedList is created:<br />

var myGroupedList = myList.createGrouped(getGroupKey, getGroupData, compareGroups);<br />

187

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!