HTML and CSS Reference
In-Depth Information
FIGURE 10-11 Creating a new task and refreshing the task list.
Saving tasks to the roaming folder
When the user clicks to add or update the task, the current version of the code invokes the TodoList.
pickFileAndSaveTask method. This method in turn uses the file picker to find the file and saves content
to it. You can keep the same method name and just rewrite its body, as shown below:
var task = TodoList.getTaskFromUI();
var localFolder = Windows.Storage.ApplicationData.current.roamingFolder;
var name = task.description;
var io = Windows.Storage.FileIO;
var fileOptions = Windows.Storage.CreationCollisionOption;
localFolder.createFileAsync(name, fileOptions.replaceExisting)
.done(function (file) {
io.writeTextAsync(file, TodoList.serializeTask(task))
.done(function () {
TodoList.alert("All done!");
TodoList.populateTaskList();
TodoList.cancelTaskClick(); // clears the UI after saving
})
},
function (error) {
TodoList.alert("Unable to create file. Sorry about that!");
});
Search WWH ::




Custom Search