我已经阅读了几篇帖子,但我仍然无法访问嵌套对象数据。我正在使用工厂使用jsonp获取天气信息:
this.testApi = function(coords) {
var deferred = $q.defer();
$http.jsonp(API_ROOTS + '?key=khjsgf7bhv3y3hy776763&q=' + coords.latitude + ',' + coords.longitude + '&cc=yes&includeLocation=yes&format=json&callback=JSON_CALLBACK')
.then(function(response) {
deferred.resolve(response.data);
console.log(response.data.data);
}, function(error) {
deferred.reject(error);
}
);
return deferred.promise;
};
这将返回如下所示的响应:
Object {current_condition: Array[1], nearest_area: Array[1], request: Array[1], weather: Array[5]}
现在里面,比方说,current_condition,它看起来像这样:
0: Object
FeelsLikeC: "17"
FeelsLikeF: "63"
cloudcover: "0"
humidity: "23"
observation_time: "09:51 AM"
precipMM: "0.0"
pressure: "1028"
temp_C: "17"
temp_F: "63"
visibility: "10"
weatherCode: "113"
weatherDesc: Array[1]
weatherIconUrl: Array[1]
winddir16Point: "WSW"
winddirDegree: "250"
windspeedKmph: "7"
windspeedMiles: "4"
__proto__: Object
length: 1
__proto__: Array[0]
唯一的问题是,当我尝试在我的HTML中访问它时,我没有得到任何结果:
{{place.current_condition.FeelsLikeC}}
似乎没有输出任何东西......
答案 0 :(得分:2)
如果地方是javascript对象,那么您可以使用
places.current_condition[0].FeelsLikeC
如果地方是数组,则可以使用类似
的内容places[0].current_condition[0].FeelsLikeC
current_condition 是一个数组。