如果它在数组中,如何获取对象属性?

时间:2015-05-29 16:19:46

标签: javascript angularjs

我有这样的js对象结构:

Object {
    name: "name";
    id: "id";
    subGroups_id : Array[1] 0: 9
}

我想获取subGroup_id并根据子组的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();
}]);

如果你能解释我怎么做,我真的很感激

谢谢。

1 个答案:

答案 0 :(得分:0)

假设群组名称位于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
相关问题