【发布时间】:2018-11-08 17:16:40
【问题描述】:
我正在尝试添加一个复选框来选择/取消选择所有项目,然后对所有项目求和。我已经为它做了一些代码。但是,这两个功能现在是分开的,我想将它们合并在一起以实现目标。
HTML
//Select all checkbox
<input type="checkbox" ng-change="checkAll()" ng-model="params.checkbox[0]"
class="ng-valid ng-dirty ng-valid-parse ng-touched ng-empty" style="">
//Select a single checkout and do cal balance
<input type="checkbox" name="marked_reconciled" ng-
model="trx.marked_reconciled" ng-change="calBalance()">
这是 AngularJs
$scope.checkAll = function () { angular.forEach($scope.records, function (v)
{ $scope.params.checkbox[v.id] = $scope.params.checkbox[0]; }); };
$scope.calBalance = function () {
if (!$scope.trans) {
return;
}
var current = 0;
var statement_mth = new Date($scope.item.reconcile_date).getMonth();
angular.forEach($scope.trans.trans, function (trx) {
var reconcile_mth = new Date(trx.reconcile_on).getMonth();
if (trx.marked_reconciled && ((statement_mth == reconcile_mth) || !trx.reconcile_on)) {
if (trx.entry == 'debit') {
current += parseFloat(trx.amount);
} else if (trx.entry == 'credit') {
current -= parseFloat(trx.amount);
}
}
});
};
我尝试将 ng-change 合并为 "checkAll();calBalance()" 但不起作用。
【问题讨论】:
-
你的html里只有两个复选框?还有其他复选框吗?
-
@Nabil Shahid 表格正文中有其他复选框,表格第一行有“全选”复选框。
标签: javascript angularjs checkbox angularjs-ng-change