javascript - Azure Mobile Services - table.read().done(function (results)) returning undefined values -


edit: function asynchronous console.log fired before data returned. i'll putting logic inside .done() function now.

i'm trying take results array , pass global variable variable logging undefined outside of results function.

it array need inside function.

i need have array of objects outside of results function cannot debug inside function , have alot of code write

here code

$scope.synccontacts = function () {            var table = azureservice.gettable('contact');          var contactlist = [];          table.read().done(function (results) {              contactlist = results;              (var = 0; < results.length; i++) {                  console.log("contact object:", results[i]);              }              console.log('contact list : ', contactlist);          });          console.log("outside function list", contactlist);      };

i have been reading around , have seen function response.send(200, results) being used in azure tables have no idea used or if need it.

there's variable scope issue wth contactlist, print outside variable, , creating new 1 inside promise populate.

var table = azureservice.gettable('contact'); table.read().done(function (results) {    $scope.contactlist = results;    (var = 0; < results.length; i++) {      console.log("contact object:", results[i]);    }    console.log('contact list : ',$scope.contactlist); }); 

here's oficial documentation azureservice javascript: add mobile services existing app

edit:

the contactlist being printed undefined because of promise resolution. done method take time data server. but, if print inside done, show result, expected. should put value inside $scope variable, can use after read returns data server:


Comments