如何从网格中删除项目时重置数组?

时间:2016-03-18 21:57:46

标签: javascript angularjs

打开时我有一个模态窗口我有网格,我将$scope.controlDTO.controlOwners设置为$scope.selectedOwners数组,即grid dataSource,现在当我使用$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();
      });
    };

2 个答案:

答案 0 :(得分:1)

问题在我看来,每次打开模态时,都会复制class CorrosionAddSampleTreatmentFormViewController: BaseViewController, SampleTreatmentFormViewDelegate, UIPickerViewDataSource,UIPickerViewDelegate,UICollectionViewDataSource, UICollectionViewDelegate { var corrosionAddSampleFormView : SurfaceThermalSamplingAddSamplingView! var selectedCorrosionErMeasurementID : String! override func viewDidLoad() { print("Selected ID from FormCorrosionER is: \(self.selectedCorrosionErMeasurementID)") super.viewDidLoad() } } ,但在删除时,您只能从$scope.controlDTO.controlOwners中删除。在删除时添加一个拼接到$scope.selectedOwners,它应该可以工作。

答案 1 :(得分:0)

当您从func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } 删除所有者时,它不会从$scope.selectedOwners中删除,因此您还希望将其从该数组中删除。