繁体   English   中英

如何访问对象数组中的对象?

[英]How can i access object inside array of object?

我有控件Owners json对象,所以我试图从中获取worker,如何将worker json对象分配给$scope.controlOwnerObj.worker

ctrl.js

if ($state.is('app.editControl')) {
          angular.forEach($scope.controlDTO.controlOwners,function(owner){
            $scope.selectedOwners = owner 
          })
         // $scope.selectedOwners = $scope.controlDTO.controlOwners[0].worker;
//        $scope.controlDTO.controlOwners[0].worker.fullName;
          console.log('EDIT CONTROL OWNERS DATA', $scope.selectedOwners);
        }

json.js

"controlOwners": [{
    "worker": {
        "workerKey": -1093,
        "sourceFeed": null,
        "statusLookUpCode": null,
        "externalId": null,
        "createdUserText": null,
        "createdTimestamp": null,
        "modifiedUserText": null,
        "modifiedTimestamp": null,
        "stdId": "ZK84T1N",
        "ccId": null,
        "empClasId": null,
        "deptId": null,
        "fullName": "Rajasekaran, Shanmuga",
    }
}],

指定所需的数组索引:

$scope.controlOwnerObj.worker = $scope.controlOwners[0].worker;

尝试像这样使用

$scope.controlOwners[0].worker.fullName = 'Rajasekaran, Shanmuga';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM