问题
Does anyone know why when I click on different radio values multiple times, my Dynamic Total value changes drastically? The code below should automatically select the column of checkboxes according to the radio buttons. Not sure why there would be miscalculations.
switch($scope.ChangeAll.name) {
case 'x':
row.xBox = true;
row.yBox = false;
row.zBox = false;
break;
case 'y':
row.xBox = false;
row.yBox = true;
row.zBox = false;
break;
case 'z':
row.xBox = false;
row.yBox = false;
row.zBox = true;
break;
default:
row.xBox = true;
row.yBox = false;
row.zBox = false;
}
https://plnkr.co/edit/bAnz9kCuKWGIfWD4lEO2?p=preview
回答1:
This tweak should do it.
AngularJS Controller (relevant code change):
$scope.updateSelection = function(value) {
switch ($scope.ChangeAll.name) {
case 'x':
angular.forEach($scope.myData, function(row, idx) {
row.xBox = true;
row.yBox = false;
row.zBox = false;
});
break;
case 'y':
angular.forEach($scope.myData, function(row, idx) {
row.xBox = false;
row.yBox = true;
row.zBox = false;
});
break;
case 'z':
angular.forEach($scope.myData, function(row, idx) {
row.xBox = false;
row.yBox = false;
row.zBox = true;
});
break;
default:
angular.forEach($scope.myData, function(row, idx) {
row.xBox = true;
row.yBox = false;
row.zBox = false;
});
}
};
And the all important Plunker update, https://plnkr.co/edit/QOkoG9pC7gETvZ4I7Xkq?p=preview.
来源:https://stackoverflow.com/questions/43015734/ui-grid-column-summation-on-checkbox-change