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.

}<br />

return groupCompareGlobalized(left, right);<br />

function filteredLengthFromKey(key) {<br />

var filteredList = myList.createFiltered(function (item) {<br />

return key == getGroupKey(item);<br />

});<br />

}<br />

return filteredList.length;<br />

Debugging Your Grouping Functions<br />

If your various grouping functions don’t seem to be working right, you can set breakpoints and<br />

step through the code a few times, but this becomes tedious as the functions are called many,<br />

many times for even modest collections. Instead, try using console.log to emit the parameters<br />

sent to those functions and/or your return values, allowing you to review the overall results much<br />

more quickly. To see what’s coming into the group sorting function, for example, try this code:<br />

console.log("Comparing left = " + left + " to right = " + right);<br />

ListView in the Grid App Project Template<br />

Now that we’ve covered the details of the ListView control and in-memory data sources, we can finally<br />

understand the rest of the Grid App project template in Visual Studio and Blend. As we covered in the<br />

”The Navigation Process and Navigation Styles” section of Chapter 3, “App Anatomy and Page<br />

Navigation,” this project template provides an app structure built around page navigation: the home<br />

page (pages/groupedItems) displays a collection of sample data (see js/data.js) in a ListView control,<br />

where each item’s presentation is described by a WinJS.Binding.Template as are the group headings.<br />

Figure 5-4 shows the layout of the home page and identifies the relevant ListView elements. As we also<br />

discussed before, tapping an item navigates to the pages/itemDetail page and tapping a heading<br />

navigates to the pages/groupDetail page, and now we can see how that all works with the ListView<br />

control.<br />

The ListView in Figure 5-4 occupies the lower portion of the app’s contents. Because it can pan<br />

horizontally, it actually extends all the way across; various <strong>CSS</strong> margins are used to align the first items<br />

with the layout silhouette while allowing them to bleed to the left when the ListView is panned.<br />

191

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

Saved successfully!

Ooh no, something went wrong!