I am trying to insert an object formatted like this:
$scope.newObj = {1: "N/A", 2: "KO", 3: "OK", 4: "OK", 5: "OK", 15: "N/A", 19: "OK"}
I tried using the following for loop:
var objt = $scope.newObject;
console.log($scope.newObject[0]) // undefined
for(i=0;i<$scope.newObj.length;i++)
{
$http.post("insert?etat="+$scope.newObject[0]+"&id="+Object.keys(objt))
}
But it doesn't seem to work. I am getting undefined
everywhere. Does anyone have an idea on how to retrieve the data from that object row by row then insert the values to the service?
newObj is an object rather than a array. You have tried to use it like a array. So just a iteration code needs to modify:
Use the following code:
var objt = $scope.newObject;
for(var key in objt)
{
$http.post("insert?etat="+objt[key]+"&id="+key)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With