Question

I want to return data from multiple tables into one json object so that i can deserialize at the client side in lists of other objects. The object on the client side looks like this:

class LastSyncEntity
    {
        public List<OptionSettings> option { get; set; }
        public List<Project> project { get; set;}
    }

For this i want the json output from my custom API on azure mobile services to look like this:

{
   [
      {option object 1}
      {option object 2}
   ],
   [
      {project object 1}
      {project object 2}
   ],
}

How do i get the javascript on the server to make it like this? I'm completely new to javascript.

Était-ce utile?

La solution

The output for your API you mentioned isn't really valid JSON. Assuming you want something like this:

{
  "option" : [
    { "option" : "object 1" },
    { "option" : "object 2" }
  ],
  "project": [
    { "project" : "object 1" },
    { "project" : "object 2" }
  ]
}

Then you can implement the API as follows:

exports.get = function(request, response) {
    var optionTable = request.service.tables.getTable('option');
    var projectTable = request.service.tables.getTable('project');
    optionTable.where(function() {
        return true; // add any filtering for options here
    }).read({
        success: function(options) {
            projectTable.where(function() {
                return true; // add any filtering for projects here
            }.read({
                success: function(projects) {
                    var result = { option: options, project: projects };
                    response.send(200, result);
                }
            });
        }
    });
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top