HTML and CSS Reference
In-Depth Information
Tracking the Selected Item
In the displayListItems function, I updated the value of the ViewModel.State.selectedIte-
mIndex property to keep track of which item in the table element had been selected. It is now
time to define this property. Listing 2-13 shows the addition to the viewmodel.js file.
Listing 2-13. Defining the selectedItemIndex Property
/// <reference path="//Microsoft.WinJS.0.6/js/base.js" />
/// <reference path="//Microsoft.WinJS.0.6/js/ui.js" />
(function () {
"use strict";
var shoppingItemsList=new WinJS.Binding.List();
var preferredStoresList=new WinJS.Binding.List();
WinJS.Namespace.define("ViewModel", {
homeZipCode: null,
getStores: function () {
return preferredStoresList;
addStore: function (newStore) {
getItems: function () {
return shoppingItemsList;
addItem: function (newName, newQuantity, newStore) {
item: newName,
quantity: newQuantity,
store: newStore
selectedItemIndex: -1
// …test data removed for brevity …
I use the >State object to differentiate between data required for the current state of the
app and data created by the user (which is represented by the UserData object).
Search WWH ::

Custom Search