我正在尝试使用“AngularJS”在网格视图中制作一个简单的(检查并取消全部检查),但我找到的所有示例都取决于 ng-repeat ,我们将不胜感激。
问题是我使用(ng-checked)来实现我的目标,但是当选中master复选框时,子复选框不会触发 onchange 事件 所以我无法完成我的任务,根据是否选中子复选框进行一些更改
var ngGridApp = angular.module('gridApp', []);
ngGridApp.controller('mainController', ['$scope', function ($scope) {
$scope.name = "gridCtrl";
$scope.ids = {};
$scope.ConLog = function (val) {
console.log(val);
};
$scope.CheckUnCheckAll = function () {
$scope.$watch('ids', function (newValue, oldValue) {
$scope.ids = newValue;
});
}
}]);
答案 0 :(得分:0)
var ngGrigApp = angular.module('gridApp', []);
ngGrigApp.controller('mainController', ['$scope', function ($scope) {
$scope.name = "gridCtrl";
$scope.ids = [];
$scope.BindIds = (function () {
angular.element("input[id*=chkBoxSelected]").each(function () {
$scope.ids.push({ "value": this.value, "IsChecked": this.checked });
});
})();
$scope.triggerAll = function () {
angular.forEach($scope.ids, function (obj) {
if ($scope.chkBoxChief) {
obj.IsChecked = true;
}
else {
obj.IsChecked = false;
}
})
}
}]);
<强> JS Fiddle Demo 强>