gpt4 book ai didi

javascript - 如何访问对象数组内的对象?

转载 作者:行者123 更新时间:2023-11-28 18:40:58 25 4
gpt4 key购买 nike

我有control 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;

关于javascript - 如何访问对象数组内的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36092634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com