javascript - 如何在 angularjs 中迭代 $scope 变量?

标签 javascript arrays angularjs

我有这样的代码:

$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/

相关文章:

javascript - 轴上刻度值的格式

javascript - 如何在 angularjs 中使用 ng-model 调用方法

javascript - 一次点击完全完成后停止onclick事件监听所有 Action

java - Android XML dataHandler getResources() 未定义

java - 递归查找数组中数字的最小路径

javascript - 与对象数组进行比较并更新 Angular 中的键

javascript - 如何覆盖 Material 表中的 MuiPaper-root 样式

python - 在 NumPy 中计算距离矩阵的有效方法

javascript - AngularJS:$scope 与此:$scope 的用途是什么?

angularjs - 尝试使用 url 中的凭据优化我的 Angular HttpClient 调用