Skip to content

Instantly share code, notes, and snippets.

@gergob
Created November 24, 2012 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gergob/4141769 to your computer and use it in GitHub Desktop.
Save gergob/4141769 to your computer and use it in GitHub Desktop.
Process and display zoo.json
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