Created
November 24, 2012 23:16
-
-
Save gergob/4141769 to your computer and use it in GitHub Desktop.
Process and display zoo.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
args.setPromise(WinJS.UI.processAll().then(function() { | |
//build up the URL for the file added to the project | |
var url = new Windows.Foundation.Uri("ms-appx:///zoo.json"); | |
//this will store the imported data | |
var myNewAnimals = new Array(); | |
//invoke the static method which loads the file | |
//and creates Animal objects from json data | |
//THE METHOD RETURNS A PROMISE!!! | |
Zoo.Animal.loadZoo(url).done( | |
function (result) { | |
myNewAnimals = result; | |
myNewAnimals.forEach(function (animal) { | |
console.log("Name: " + animal.getName() + ", Age: " + animal.getAge() + ", IsHungry: " + animal.isHungry() + ", Hours since Last feed: " + animal.getHoursSinceLastFeed()); | |
}); | |
}, | |
function (error) { | |
var messDialog = new Windows.UI.Popups.MessageDialog(error); | |
messDialog.showAsync(); | |
}); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment