[英]How can i assign array of object to array?
我现在有一个来自后端的json响应controlOwners
,我想将响应设置为$scope.selectedOwners = []
,但是它在控制台中给我未定义的任何提示这是怎么了?
ctrl.js
$scope.selectedOwners = [];
if ($state.is('app.editControl')) {
$scope.selectedOwners = angular.copy($scope.controlowners);
console.log('EDIT CONTROL OWNERS DATA', $scope.selectedOwners);
}
json.js
"controlOwners": [{
"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",
}],
正如我在上面的评论中所述,我的猜测是您对controlOwners的引用中包含不正确的大小写。 您应将其拼写为小写字母“ o”(“ controlowners”),而应将其拼写为大写(“ controlOwners”)。 因此,您将收到未定义的错误。
首先请确保这不是拼写错误。 你们两个都有:
controlOwners
^
和
controlowners
^
在JSON和代码中。
然后,如果拼写错误只是您的问题而不是您的代码,并且取决于您在其他地方使用$scope.selectedOwners
,则您可能不想替换 if语句中列表的引用,而希望对其进行更新现有列表(即使您必须先清除它)。
但是很明显,如果您的代码正好具有:
$scope.selectedOwners = [];
if ($state.is('app.editControl')) {
而不是可能在其他时间触发的回调中的if,则忽略它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.