Parser requests via nested for loops give duplicate results

I am trying to loop through an array to query my order class to find the associated identifier, and then loop another class with this id.

There are 4 elements in the original array, and they must match the identifier, each of which has 43 elements in the third query.

However, instead of getting 43 results from the 3rd request for an identifier, I get the results 12 * 43.

I can’t understand how my code is wrong, and I tried to be contained. Also without any results.

$scope.positionIds = []; $scope.dataDictionary = {}; $scope.quotes = function () { for (var i=0; i < $scope.positions.length; i++){ var positionNow = $scope.positions[i]; var orderQuery = new Parse.Query('Order'); orderQuery.equalTo('objectId', positionNow ); orderQuery.find({ success: function(result) { console.log(result); for (var j=0; j < result.length; j++){ $scope.positionIds.push(result[j].attributes.positionId); } for (var k=0; k < $scope.positionIds.length; k++){ var portfolioQuery = new Parse.Query('DayPosition'); portfolioQuery.limit(1000); var positionSecond = $scope.positionIds[k]; portfolioQuery.equalTo('positionId', positionSecond); console.log("positionId", $scope.positionIds[k]); portfolioQuery.find({ success: function(result) { console.log("count", result.length); for (var h=0; h < result.length; h++){ // console.log("count", result.length); console.log("double inside data time", result[h].createdAt); console.log("double inside data id", $scope.positionIds[k]); console.log("value", result[h].attributes.currentValue); var values = []; values.push([result[h].createdAt, result[h].attributes.currentValue]); if (!$scope.dataDictionary[result[h].attributes.positionId]){ $scope.dataDictionary[result[h].attributes.positionId] = []; } else { $scope.dataDictionary[result[h].attributes.positionId].push(values); } } console.log("final data", $scope.dataDictionary); }, error: function (error) { console.log("this error", error); } }); } }, error: function (error) { console.log("this error", error); } }); } }; 
+4
source share

All Articles