0
類似於我發佈的另一個問題,我有一個問題,抓住一週的天氣和分配不同的行。基本上我想要的格式是:JSONP角度js顯示多個對象
Mon Tues Wed Thurs
悉尼25 21 21 22
墨爾本26 18 21 24
等 不幸它被抓住所述陣列的所述第一部分和coppying該所有區域。
這裏是我的JS:
app.controller('forecastCtrl',function($scope, $http){
$scope.weatherDataSydney = null;
$scope.weatherDataBrisbane = null;
$scope.weatherDataPerth = null;
$scope.weatherDataMelbourne = null;
$scope.weatherDataAdelaide = null;
$scope.weatherDataDarwin = null;
$http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Sydney.json?callback=JSON_CALLBACK').success(function(data){
$scope.weatherDataSydney=data;
});
$http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Brisbane.json?callback=JSON_CALLBACK').success(function(data){
$scope.weatherDataBrisbane=data;
});
$http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Melbourne.json?callback=JSON_CALLBACK').success(function(data){
$scope.weatherDataMelbourne=data;
});
$http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Perth.json?callback=JSON_CALLBACK').success(function(data){
$scope.weatherDataPerth=data;
});
$http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Darwin.json?callback=JSON_CALLBACK').success(function(data){
$scope.weatherDataDarwin=data;
});
$http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Cairns.json?callback=JSON_CALLBACK').success(function(data){
$scope.weatherDataCairns=data;
});
$http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Adelaide.json?callback=JSON_CALLBACK').success(function(data){
$scope.weatherDataAdelaide=data;
$scope.cityForecasts=[
{ name:'Sydney',
high: $scope.weatherDataSydney.forecast.simpleforecast.forecastday
},
{ name:'Brisbane',
high: $scope.weatherDataBrisbane.forecast.simpleforecast.forecastday
},
{ name:'Melbourne',
high: $scope.weatherDataMelbourne.forecast.simpleforecast.forecastday
},
{
name:'Adelaide',
high: $scope.weatherDataAdelaide.forecast.simpleforecast.forecastday
},
{ name:'Darwin',
high: $scope.weatherDataDarwin.forecast.simpleforecast.forecastday
},
{ name:'Perth',
high: $scope.weatherDataPerth.forecast.simpleforecast.forecastday
},
{ name:'Cairns',
high: $scope.weatherDataCairns.forecast.simpleforecast.forecastday
},
]
});
$scope.getForecast = function() {
for(i=1; i < 2; i++){
for(x=0;x<1;x++){
return($scope.cityForecasts[i].high[x].high.celsius);
}
}
}
});
下面是HTML
<div id="forecast-container">
<div class="forecast" ng-repeat="cityForecast in cityForecasts">
<div class="city-forecast">
<span>{{cityForecast.name}}</span>
</div>
<div class="list-days">
<ul class="day">
<li id="day1">Mon</li>
<li id="day2">Tues</li>
<li id="day3">Wed</li>
<li id="day4">Thur</li>
</ul>
</div>
<div class="temp-list">
<ul >
<li class="temp" ng-repeat="forecast in weatherDataSydney.forecast.simpleforecast.forecastday">
{{getForecast()}}
</li>
</ul>
</div>
</div>