我有这样的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();
}]);
如果你能解释我怎么做,我真的很感激
谢谢。
答案 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