search

Home  >  Q&A  >  body text

How to store a json formatted value in a loop

Now we are calling a method repeatedly, in the method
function getSecondInfo(ID) {
$http({

url: "http://192.168.199.239:8013/Productions/GetProductionsByID?ProductionID=" + ID,
 method: 'get'
   }).success(function(data) {
            $scope.json[ID] = data[0];
        });
        $scope.ManJsonArr.push($scope.json);
    }
    
    上述方法是在一个循环中调用,id值是循环中的i值  我每次循环都会为json赋值,最后执行完上述循环,json的值是最后一次执行的还是结果,还是所有的执行的结果
漂亮男人漂亮男人2816 days ago446

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 13:24:13

    is all all

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:24:13

    This is equivalent to calling the function ajax request to pass in the url parameters every time you loop, then $scope.ManJsonArr stores the values ​​of all your push

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:24:13

    $scope.json contains all the values ​​obtained by ajax

    However, $scope.ManJsonArr will have n (n is the number of loops) identical $scope.json objects

    reply
    0
  • Cancelreply