我发出parse.com
get请求,返回的数据存储在:
$scope.tastes = data.results
{
"createdAt": "2016-03-16T07:39:15.745Z",
"objectId": "Cmg8GdOv2Z",
"updatedAt": "2016-03-16T07:39:15.745Z",
"user": {
"__type": "Pointer",
"className": "_User",
"objectId": "vYOsndWlto"
},
"userTastes": [
{
"actualite": {
"checked": true
},
"economie": {
"checked": true
},
"entrepreneuriat": {
"checked": false
}
}
]
}
好吧,我想获得userTastes数组。
我试过
.success(function (data, status) {
$scope.tastes = data.results.userTastes;
console.log($scope.tastes);
})
但是没有返回任何内容。我想我错过了什么。
我的问题:如何在$ scope.tastes中获取userTastes?
答案 0 :(得分:0)
结果[0] .userTastes工作完美谢谢!
如果有人在JS中有关于数组和对象的教程链接或好的课程,因为我对此有点困惑。
祝你有个美好的一天!
答案 1 :(得分:0)
我写了一个单独的答案,因为我认为这需要进一步解释,而不仅仅是解决你的问题。
您只在问题中提供了一个对象响应,但显然您从服务器获得了一个数组响应,而您可以直接访问对象字段,首先需要访问该位置的数组对象,例如:
$scope.objectResponse = {"foo":"bar"};
console.log($scope.objectResponse.foo); // Will print "bar"
对比阵列响应:
$scope.arrayResponse = [{"foo":"bar"}];
console.log($scope.arrayResponse[0].foo); // Will print "bar"
确保从服务器获得所需的响应。