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

Gary McNeill

EDIT: The function is asynchronous so console.log was fired before the data was returned. I'll be putting my logic inside this .done() function now.

I'm trying to take the results array and pass it into a global variable but the variable is logging as undefined outside of the results function.

It is however the array I need INSIDE the function.

I need to have an array of objects OUTSIDE of the results function as I cannot debug inside this function and have alot of code to write

Here is the code

$scope.syncContacts = function () {

        var table = AzureService.getTable('contact');
        var contactList = [];
        table.read().done(function (results) {
            contactList = results;
            for (var i = 0; i < results.length; i++) {
                console.log("Contact Object:", results[i]);
            }
            console.log('contact list is : ', contactList);
        });
        console.log("OUTSIDE FUNCTION LIST", contactList);
    };

I have been reading around and have seen a function response.send(200, results) being used in azure tables but have no idea what its used for or if I need it.

Fals

There's a variable scope issue wth contactList, you are print the outside variable, and creating a new one inside the promise to populate.

var table = AzureService.getTable('contact');
table.read().done(function (results) {
   $scope.contactList = results;
   for (var i = 0; i < results.length; i++) {
     console.log("Contact Object:", results[i]);
   }
   console.log('contact list is : ',$scope.contactList);
});

Here's the oficial documentation for AzureService JavaScript: Add Mobile Services to an existing app

EDIT:

The contactList is being printed undefined because of the promise resolution. The done method will take some time to get the data from the server. But, if you print it inside the done, It will show up the result, as expected. You should put this value inside a $scope variable, then you can use It after the read returns the data from the server:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Crafting JSON for Multiple Results in Azure Mobile Services

Exception on Update azure mobile services data table

Azure Mobile Services : GET operation from table

Azure Mobile Services / Azure Table: How to handle list of "members"

Azure mobile services exception in android, table does not exist

Azure Mobile Services Latency

Azure Mobile Services / Authentication

JSON returning undefined values

Azure Mobile Services and Application Insights

Node domains on Azure Mobile Services

Architecture of Azure Mobile Services Application

Azure Mobile Services - Local DB

Azure Mobile Services with persistent authentication

Implementing Azure Mobile Services with OAuth and Not

Android Login with Azure Mobile Services

Sorting Query Azure Mobile services

Why am i having an error: Cannot read property 'results' of undefined when returning an API data?

Azure DocumentDB - Query returning no results

Azure Search returning incorrect results

Joined table not returning any results

How to insert multiple objects in to Azure Mobile Services table controller [.Net backend]

Why is Entity Framework generating the following nested SQL for Azure Mobile Services Table Controllers

Create new SQL table for Azure Mobile Apps/Services w/ .NET backend

MariaDB is returning undefined once I export the results

Ajax results giving undefined values

Implement Custom Authentication In Windows Azure Mobile Services

Update on TableController in Azure Mobile Services fails

Azure Charging for SQL Databases for push in mobile services

Azure C# Mobile Services Status Route

TOP Ranking

HotTag

Archive