HTML and CSS Reference
In-Depth Information
Defining the task object
Most of the JavaScript code inserted in HTML pages deals with updating elements. Data binding is a
powerful technique to keep this necessary code to a bare minimum, assigning the burden of doing
most of the work to the underlying framework. For data binding to work seamlessly, you should
create an object that closely matches the data you plan to read and write through the form. In this
case, you need a Task object. To create it, add a new JavaScript file to the Js folder of the project. You
may name it after the application— TodoList.js .
Before you get to edit the todolist.js file, a small change is required in the default.js file to take
control of the loading phase of the application. It's the same change you made in the data binding
example discussed in the previous chapter. In general, this change is required in any Windows Store
application. You locate the app.onactivated function and just replace the line that calls into the
setPromise method with the code below:
args.setPromise(WinJS.UI.processAll()
.then(TodoList.init())
);
The effect of this code is yielding control to the function named TodoList.init after the activation
phase has completed.
Now, turn your attention to the newly created todolist.js file and add the following code to it:
var TodoList = TodoList || {};
TodoList.init = function () {
TodoList.performInitialBinding()
}
TodoList.Priority = {
VeryLow: 1,
Low: 2,
Normal: 3,
High: 4,
VeryHigh: 5
};
TodoList.firstOfNextMonth = function () {
var d = new Date();
d.setDate(d.getDate() + 31);
var year = d.getFullYear();
var month = d.getMonth();
var day = 1;
var newDate = new Date(year, month, day);
return newDate;
}
Search WWH ::




Custom Search