我的情况是后端dataItem
有值。现在我想将这些值推送到数组并设置对象属性,因此下一步是将对象属性映射到表单字段。使用下面的代码,我得到了值并将其分配给对象selectedOwners
及其工作正常,但问题是每次用户addProcessOwner
为每个用户创建新对象,而$scope.processDTO.prcsOwner = selectedOwners.fullName;
只执行此操作将最后一个值分配给表单字段。
用户选择多个所有者后,如何在表单字段中显示所有所有者?
main.html中
<input type="text" class="form-control customReadOnly"
id="prcsOwner" required ng-model="processDTO.prcsOwner"
ng-click="openPrcsOwner()" ng-disabled="PROCESS_EDIT"/>
ctrl.js
var selectedOwners = {};
$scope.selectedOwnerGrid = rcsaAssessmentService.selectedProcessOwners();
$scope.addProcessOwner = function(dataItem) {
selectedOwners = {
fullName: dataItem.fullName,
workerKey: dataItem.workerKey
}
console.log('WORKER DATA', selectedOwners);
}
$scope.selectedProcessOwner = function() {
$scope.prcsOwnerModal.close();
$scope.processDTO.processOwnerWorkerKey = selectedOwners.workerKey;
$scope.processDTO.prcsOwner = selectedOwners.fullName;
console.log('FORM DATA', $scope.processDTO.processOwnerWorkerKey, $scope.processDTO.prcsOwner);
};
答案 0 :(得分:0)
我认为你要做的是:
var selectedOwners = [];
...
var selectedOwner = {
fullName: dataItem.fullName,
workerKey: dataItem.workerKey
}
selectedOwners.push(selectedOwner);