How To Populate List In Windows8 With Javascript
Solution 1:
This can not work this way, because the $.ajax function is asynchronous : it does the ajax call, and then, later, calls the "success" function with the appropriate data.
You'll have rewrite the $.each(data() ... so that instead of calling data() and expecting it to return testMeeting , you call data and expect it to call a callback with the testMetting object.
Something like :
(function () {
var list = newWinJS.Binding.List();
getData(function (theMetting) {
$.each(theMeeting, function (key, item) {
list.push(item);
});
}
})();
// callback is a function that will be called with // something that is built from the server, after the ajax// request is donefunctiongetData(callback) {
$.ajax({
// ... everything you did ... success: function (data) {
// ... use the data to build the meeting object// and pass it to the callbackcallback(meeting)
}
return testMeeting;
}
});
}
There is a fundamental difference between synchronous code (that returns functions) and asynchonous calls (that does some work, and later calls callback with the result). $.ajax is the typicall asynchronous function.
You could in theory pass the "async" flag to ajax, so that the $.ajax function does not return before the Ajax call is done, but you probably do not want to do that since it would block you UI.
Hoping this helps.
Post a Comment for "How To Populate List In Windows8 With Javascript"