我有这样的代码:
$scope.maps = [
new google.maps.LatLng($scope.longitude[0], $scope.latitude[0]),
new google.maps.LatLng($scope.longitude[1], $scope.latitude[1]),
new google.maps.LatLng($scope.longitude[2], $scope.latitude[2])];
如何以 AngularJS 风格进行简化以进行更多迭代?
最佳答案
$scope.maps = [];
$scope.longitude.forEach(function(el, i) {
$scope.maps.push(new google.maps.LatLng(el, $scope.latitude[i]));
});
// or
$scope.maps = [];
for(var i = 0; i < $scope.longitude.length; ++i) {
$scope.maps.push(new google.maps.LatLng($scope.longitude[i], $scope.latitude[i]));
}
关于javascript - 如何在 angularjs 中迭代 $scope 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34705347/