Home Add new value into json
Reply: 0

Add new value into json

user1357
1#
user1357 Published in May 27, 2018, 3:37 am

I'm tiying to build an excel uploader app. Right now, I can get the data from the excel file and send it to an API to store the info.

But i need something else, and is to asign to each value the id of the excel, which i'll get after save it first.

This is how i get the excel data before store it:

$scope.loadWorksheet = function(e){

        var file = e.target.result;
        var workbook = XLSX.read(file, { type: "binary" });


        var sheetName = workbook.SheetNames[0];
        $scope.sheet = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]);

       console.log($scope.sheet);

        $scope.$apply();

      };

Let's say i get the next array:

[{Name: "Chuck", Age: "30"},
{Name: "Marcus", Age: "18"},
{Name: "Shelly", Age: "29"}]

How can i add to each record the id of the document?

Per example, after save the document i get on the response the id:

$scope.IdDocument = 15;

And what i need is to put it on every record, like this:

[{Name: "Chuck", Age: "30", DocumentId: "15"},
{Name: "Marcus", Age: "18" DocumentId: "15"},
{Name: "Shelly", Age: "29" DocumentId: "15"}]

There's a way to do that? Hope you can help me.

I'm using AngularJs and Javascript.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.307634 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO