It appears to be the classic mistake of trying to use data that is processed after an asynchronous operation before the asynchronous operation has finished and run the callback. Whatever code needs BasketballItems
should be called as part of that code block. For example:
BasketballItems.push({ group: BasketballGroups[0], title: "hello", content: "h", backgroundImage: lightGray });
myOtherCode(BasketballItems);
and then put the code that needs to know about those items in that function. It's just another callback.
function myOtherCode(items) {
console.log(items); // <--- code in here knows about the push, since it occurs in the callback chain after the asynchronous operation (WinJS.xhr)
}
Depending on the scope, you may not need to pass in BasketballItems
as I did there. It looks like you can just access it implicitly, but I don't recommend having such non-encapsulated variables.
To clarify my meaning, you might also be able to just do this in the callback:
function myOtherCode() {
console.log(BasketballItems);
}
Of course, you could also not use a function and just dump all of your code right there instead, but it's better to try to break your code up more.