Javascript错误,值不会被推入数组

时间:2016-08-09 07:01:21

标签: javascript angularjs arrays

我正在尝试将值从一个数组推送到第二个数组,但每次输出第二个数组时,我都会得到一个空的'[]'输出

$scope.myArray = [];
$http.get("http://127.0.0.1/dbtest/init.php").then(function(response){
    $scope.myData = response.data.records;
    for(var i = 0; i < $scope.myData.length; i++){
        $scope.myArray.push({
            text: $scope.myData[i].id,
            image: $scope.myData[i].url
        });
    }
    console.log($scope.myData); //1st output this one works
});
console.log($scope.myArray); //2nd output shows empty array

enter image description here

更新: enter image description here

这是我从http请求中得到的结果

0 个答案:

没有答案