美好的一天,我正在使用离子角构建天气应用程序,我在JSON
数据中遇到天气数组的问题。
我的代码
(function() {
var app = angular.module('starter.wund', []);
app.controller('ForecastController', function($scope, $http) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var key = 'xxxxxxxx'; http://www.wunderground.com/
var service_url = "http://api.wunderground.com/api/" + key + "/forecast/geolookup/conditions/lang:AR/q/" + position.coords.latitude + "," + position.coords.longitude + ".json?callback=JSON_CALLBACK";
$http.jsonp(service_url).success(function(data) {
$scope.city = data.location.city;
$scope.temperature = data.current_observation.temp_c;
$scope.description = data.current_observation.weather;
$scope.wind_condition = data.current_observation.wind_string;
$scope.weather_icon_src = data.current_observation.icon_url;
for(i=0; i<36; i++){
var day = data.forecast.txt_forecast.forecastday[i].fcttext_metric;
$scope.forecastfuture = [];
$scope.forecastfuture.push({
id: i,
day: day,
});
}
});
}, function() {
alert("That's weird! We couldn't find you!");
});
} else {
alert('Geolocation is not supported');
}
});
})();
我遇到问题的代码是:
for(i=0; i<36; i++){
var day = data.forecast.txt_forecast.forecastday[i].fcttext_metric;
$scope.forecast = [];
$scope.forecast.push({
id: i,
day: day,
});
}
错误:data.forecast.txt_forecast.forecastday [i]未定义角度