[英]When I remove an item from a array, how to change the status to deleted?
[英]How to reset array when item is deleted from the grid?
我有一個模式窗口,當它打開時我有網格,並且我將$scope.controlDTO.controlOwners
設置為網格數據$scope.controlDTO.controlOwners
的$scope.selectedOwners
數組,現在當我使用$scope.deleteOwner
行刪除此項目時,已從網格刪除了該對象,但當您再次打開模式窗口時,將再次填充行。
我如何使用angularJs解決此問題?
ctrl.js
$scope.selectedOwners = [];
$scope.opencntrlOwner = function() {
this.ctrlOwnerModal.open().center();
if ($state.is('app.editControl')) {
$scope.selectedOwners = angular.copy($scope.controlDTO.controlOwners);
console.log('EDIT CONTROL OWNERS DATA', $scope.selectedOwners);
}
controlOwnersDataSource();
};
$scope.deleteOwner = function(dataItem) {
angular.forEach($scope.selectedOwners, function(owner, $index) {
if (owner.workerKey === dataItem.workerKey) {
$scope.selectedOwners.splice($index, 1);
}
controlOwnersDataSource();
});
};
在我看來,問題在於,每次打開模式時,您都會復制$scope.controlDTO.controlOwners
但是在刪除時,您僅從$scope.selectedOwners
中刪除。 在刪除時也將一個接頭添加到$scope.controlDTO.controlOwners
,它應該可以工作。
當您從$scope.selectedOwners
刪除所有者時,不會從$scope.controlDTO.controlOwners
中刪除$scope.controlDTO.controlOwners
,因此您也希望將其從該數組中剪接出來。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.