如何遍历数组并检索该响应的内部值并将其推送到角度数组对象。
到目前为止我所写的内容:
angular.forEach(response, function(item) {
$scope.FbPages = $scope.FbPages.concat($scope.item.name);})
Facebook的回复看起来像这样
accounts: Object
data: Array[11]
0: Object
access_token: "CAAWlw4AuZARMBALL2YV034jGClKDR32L2ZBHxP1C"
category: "Political Organization"
id: "104147073282632"
name: "Stalwarts of INC"
perms: Array[6]
__proto__: Object
1: Object
access_token: "CAAWlw4AuZARMBAN7ZB9vDiCeR1vNbDyIAyK"
category: "Computers/Technology"
id: "1495612094063208"
name: "Latch UI"
perms: Array[6]
__proto__: Object
我需要检索每个页面的名称,并将该值附加到FbPages中。
答案 0 :(得分:0)
angular.forEach(response, function(item) {
$scope.FbPages = $scope.FbPages.concat( /*$scope*/ item.name);
})
答案 1 :(得分:0)
初始化数组并按下每个项目(或相关部分):
$scope.FbPages = [];
angular.forEach(response, function(item) {
$scope.FbPages.push(item.name);
});
答案 2 :(得分:-1)
尝试如下。
设置范围变量数组。
if(angular.isArray(response.data) ) {
$scope.FbPages = [];
angular.forEach(response.data, function(item) {
$scope.FbPages.push(item.name);
});
}
ng-repeat示例:
<ul ng-repeat="user in FbPages">
<li>{{user.name}}</li>
</ul>