Angularjs ui网格删除不工作的选定行

Angularjs ui网格删除不工作的选定行,angularjs,ng-grid,angular-ui-grid,Angularjs,Ng Grid,Angular Ui Grid,当我尝试删除ng grid中的选定行时,删除的行仍显示在UI中。 我的网格选项是 $scope.gridOptions = { data: 'myData', multiSelect: true, displaySelectionCheckbox: true, selectedItems: $scope.mySelections, showFooter: true, showColumnMenu:false, showFilter :fal

当我尝试删除ng grid中的选定行时,删除的行仍显示在UI中。 我的网格选项是

$scope.gridOptions = {
    data: 'myData',
    multiSelect: true,
    displaySelectionCheckbox: true,
    selectedItems: $scope.mySelections,
    showFooter: true,
    showColumnMenu:false,
    showFilter :false,
    enableCellEdit: false,
    enableCellSelection: false,
    enableRowSelection: false,
    showSelectionCheckbox: false,
    beforeSelectionChange: function() {
      return $scope.option.enableRowSelection;
    },
}

我使用

$scope.removeItem=function(){   
    angular.forEach($scope.mySelections, function(row, index){
      angular.forEach($scope.myData, function(data, index){
        if(data.indexno == row.indexno){
          $scope.myData.splice(index,1);
          $scope.gridOptions.data = 'myData';
         console.log("after",$scope.myData);
         console.log("after data",$scope.gridOptions.data);
        }
      });
    });
    $(".badge").html($scope.mySelections.length);

}

任何建议或解决方案,请

我删除一行的方式是只允许用户一次选择一行,但您可以这样做,以便删除用户选择的所有内容。这是我用来实际执行删除操作的代码行

$scope.GridOptions.data.splice($scope.GridApi.grid.renderContainers.body.visibleRowCache.indexOf($scope.selectedRow), 1);
但我是这样做的。这是我的网格选项,位于我的控制器顶部,带有一个保存所选行的变量。但是,您可以将其设置为选定行的数组

$scope.selectedRow = null;
$scope.GridOptions = {
        enableSorting: true,
        enableRowSelection: true,
        enableRowHeaderSelection: false,
        enableColumnResizing: true,
        columnDefs: [
          { name:'User Name', field: 'username', width: '15%', minWidth: 100},
          { name:'Dependency Key', field: 'id', width: '20%', minWidth: 100},
          { name:'Dependency File', field: 'file', width: '30%', minWidth: 100},
          { name:'Modified By', field: 'modifiedBy', width: '15%', minWidth: 100},
          { name:'Modified On', field: 'modifiedOn', width: '10%', minWidth: 100, cellTemplate:'<div class="ui-grid-cell-contents">{{grid.appScope.convertDate(row.entity.modifiedOn)}}</div>'},
          { name:'Dep. File Checksum', field: 'checksumAmericas', width: '10%', minWidth: 100}
        ],
        onRegisterApi : function(gridApi) {
                $scope.GridApi = gridApi;
            }
        };
$scope.GridOptions.multiSelect = false;
然后,当用户单击remove按钮时,它调用一个方法,在该方法中,我检查$scope.selectedRow是否为null,然后从表中删除只需1行

if($scope.selectedRow != null)        
    $scope.GridOptions.data.splice($scope.GridApi.grid.renderContainers.body.visibleRowCache.indexOf($scope.selectedRow), 1);
此网站确实有助于实现ui网格功能:


希望这能有所帮助

我尝试了谷歌冲浪的所有想法,但都没有成功。你能做一把小提琴吗?$scope.myData是如何定义的?它必须是一个对象。此外,您正在修改正在循环的数据。您最好使用for循环,当您找到匹配的索引时可以中断该循环,这样您就不会像forEach那样继续处理。尝试收集要删除的索引,然后循环该列表并在最后删除它们,这样就不会修改正在循环的列表。
if($scope.selectedRow != null)        
    $scope.GridOptions.data.splice($scope.GridApi.grid.renderContainers.body.visibleRowCache.indexOf($scope.selectedRow), 1);