Sachin Sharma
Sachin Sharma

Reputation: 417

How to extract and send data having multiple and varying models in angularjs

So I have angular.js App, in which form has basically 2 models. But first model can have multiple instances

For e.g. Journal can have more than 1 author.

It is not constant how many instances of first model will be there, user can add as many he likes.

Right now I am extracting fields using

 var form = $("#form");
            var response = JSON.stringify(form.serializeArray());
            BuilderAPIService.make(response).success(function(response){
               alert("Done");
            }); 

Issue with this is that it gives me name value pairs, however I want key-value as it is more easy to handle. What is the most effective way to extract and send form data to server so that it is easy to manipulate data?

Upvotes: 0

Views: 56

Answers (1)

Diana R
Diana R

Reputation: 1174

The journal data should contain a list of authors. This means your json object should look like:

journal= {
   name :'test  1',
   description :'test description',
   authors : [ 
             {author_name:'James', author_age: 38},
             {author_name:'Kate',author_age: 25}
            ]
}

Upvotes: 1

Related Questions