0

I have a JSON file in my server and an angularJS code that reads it like this:

 $http.get('route/to/json/file.json').success(function(data) {

            $scope.watchesdata = data;

            var tmpList = [];

            for (var i = 0; i <= limit; i++){
            tmpList.push({
                Time: $scope.watchesdata[i].balance,
                Company : $scope.watchesdata[i].company,
                Matter: $scope.watchesdata[i].address
            });
          }  

            $scope.list = tmpList;    

        });   

After some more code that is not important, I update an specific 'Time' value and i want the JSON file on my server to update its information too, something like :

"If company==something and matter==something then oldTime = newTime"

I've just found how to add data at the end of a JSON, but i need to look for a specific entry and modify just one field.

2
  • 4
    you need to use server code to update file. Strongly suggest you use a database or data storage service rather than manage your own in hard files. Commented Oct 20, 2015 at 14:20
  • "I've just found how to add data at the end of a JSON" if you can add it to the end, surely you can figure out how to add it to the middle (assuming you're actually adding it to the end in a way that results in valid json) Commented Oct 20, 2015 at 14:48

1 Answer 1

1

Assuming I'm understanding your question correctly, something like this would work:

function updateTime(company, matter, newTime) {
    $scope.list.forEach(function (item) {
        if (item.Company == company && item.Matter == matter) {
            item.Time = newTime;
        };
    });
};

You would have to POST this data back to your server, as JSON, to update your server side though. It's unclear if you are asking how to do that part too.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I didn't know that. TY!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.