[英]AngularJS - Controller JavaScript $http.get
我有以下代码从JSON获取信息。
$http.get('http://localhost:3000/folder/'Id)
.success(function (response) {
console.log("response ", response);
console.log("words: ", response.result.all.Word);
})
.error(function (response) {
console.log("error");
});
但是我有一个问题要获取数组中的信息:
TypeError: Cannot read property 'all' of undefined
作为回应,我有:
response [Object, Object]
0: Object
_id: "543e95d78drjfn38ed53ec"
result: Object
all: ObjectWord: Array[17]
0: "word1"
1: "word2"
2: "word3"
...
谢谢你的帮助!
您的response
似乎是2个对象组成的数组。
更换:
console.log("words: ", response.result.all.Word);
附:
for(var i = 0; i < response.length; i++){
console.log("words: ", response[i].result.all.Word);
}
这应该遍历响应中的两个对象,并记录相关的单词。
您缺少索引,请尝试以下代码:
response[i].result.all[j] where j=0....n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.