[英]How do I access properties of an object that's inside of an array that's inside of an array that's inside of an array?
[英]How to get object properties if it's inside an array?
我有這樣的js對象結構:
Object {
name: "name";
id: "id";
subGroups_id : Array[1] 0: 9
}
我想獲取subGroup_id並根據subGroup的ID轉換為子組的名稱,我正在使用angularjs
並且這樣做:
var users = angular.module('groups', ['app']);
users.controller('groupsCtrl', ['$scope', 'apiService', 'rpcService', function($scope, apiService){
function getGroupsList() {
$scope.groupsList = [];
apiService.getGroups(0)
.success(function (data) {
$scope.groupsList = data;
console.log($scope.groupsList);
})
.error(function (data, status, headers) {
});
};
getGroupsList();
}]);
如果您能說明我該怎么做,我將不勝感激
謝謝。
假設組名稱在groupsList
$scope.groupsList[yourObj.subGroups_id][0]
-
yourObj.subGroups_id // Array[1] 0: 9
yourObj.subGroups_id[0] // 9
$scope.groupsList[9] // value at index 9 assuming it is group name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.