簡體   English   中英

如何在angularjs中的$ scope變量上迭代?

[英]How to iteration on $scope variable in 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])); } 

只是為了闡明CodeiSir的答案。 他展示的不是JavaScript的“ Angular”迭代。 您也可以將其用於讀取數據,因為您在html中使用了角度ng-repeat。

更多信息在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM