我是AngularJS的新手。请看一下:
现在,当用户点击“全部”链接时,应检查所有 11个复选框,当用户点击“无”链接时,所有 11个复选框应该取消选中。
另外,当用户选中所有其他复选框时,应检查所有底部 9复选框,并在用户取消选中所有其他时复选框,应取消选中所有底部 9复选框。
我能够一次完成任务之一,但不能同时完成。 那么,有人可以帮我同时完成这两项任务吗?
任何帮助将不胜感激。
答案 0 :(得分:3)
您可以使用
<强> HTML 强>
<body ng-controller="MainCtrl">
<button ng-click="selectAll()">Select All</button>
<button ng-click="clearAll()">Clear All</button>
<input type="checkbox" ng-model="select" ng-click="checkAll()" />
<br />
<p>Checkboxes</p>
<input type="checkbox" ng-repeat="c in checkbox" ng-model="checkbox[$index].selected">
</body>
<强>角强>
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.checkbox = [
{
selected: false
},
{
selected: false
},
{
selected: false
}
];
// Check/uncheck all boxes
$scope.selectAll = function () {
$scope.select = true;
angular.forEach($scope.checkbox, function (obj) {
obj.selected = true;
});
};
$scope.clearAll = function () {
$scope.select = false;
angular.forEach($scope.checkbox, function (obj) {
obj.selected = false;
});
};
$scope.checkAll = function () {
angular.forEach($scope.checkbox, function (obj) {
obj.selected = $scope.select;
});
};
});
参考fiddle
答案 1 :(得分:2)
HTML
<button ng-click="selectAll()"> all</button>
<div ng-repeat="item in items">
<input type="checkbox" ng-model="selected[item.id]">
</div>
JQuery
$scope.selected = {};
$scope.selectAll= function(){
for (var i = 0; i < $scope.items.length; i++) {
var item = $scope.items[i];
$scope.selected[item.id] = true;
}
};
答案 2 :(得分:0)
你可以使用NSLog(@"In didReceiveRemoteNotification badge number is %ld",(long)[UIApplication sharedApplication].applicationIconBadgeNumber);
[UIApplication sharedApplication].applicationIconBadgeNumber += [[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] integerValue];
NSLog(@"In didReceiveRemoteNotification badge number is %ld",(long)[UIApplication sharedApplication].applicationIconBadgeNumber);
它让你更容易
答案 3 :(得分:0)
<md-checkbox ng-click="checked = !checked; check = {}"></md-checkbox>
<div ng-repeat="item in [1,2,3,4,5]">
<md-checkbox ng-checked="checked || check[item]" ng-click="check[item] = !check[item]" ng-model="sel[item]"></md-checkbox>
</div>