首页 > 解决方案 > AngularJs ui-grid onRowSelectionChanged 没有更新变量值,它始终具有默认值

问题描述

上次我检查时(两三个月前)它运行良好,它们是一个使用默认布尔值 false 调用的变量,如下所示。

$scope.IsRowSelected = false;

我应该提到调试器何时在第一次设置为 true 时运行。但它来删除功能然后值读取默认值。我不明白如何处理这个错误。

代码如下:

 $scope.IsRowSelected = false;
   
$scope.gridOptions.onRegisterApi = function (gridApi) {
     $scope.gridApi = gridApi;
     gridApi.selection.on.rowSelectionChanged($scope, function (row) {
         //$scope.selectedEmpID = row.entity.id;
         debugger;
         $scope.selectedEntity = row.entity;
         $scope.Check = true;
         $scope.IsRowSelected = true;
         //in here it shows IsRowSelected as true
     });
}
 
$scope.DeleteEntity = function () {
     debugger;
     //when this funtion excecute the IsRowSelected = false
     if ($scope.IsRowSelected == true) {
         var selectedRow = $scope.selectedEntity;
     }
}
    
    
 

标签: javascriptangularjsangular-ui-gridui-grid

解决方案


取消选择行时调用gridApi.selection.on.rowSelectionChanged函数,将noUnselect属性设置为true,因此无法取消选择行。

$scope.gridApi.selection.getSelectedRows();

使用此代码从网格中获取选定的行。

工作小提琴


推荐阅读