Pai*_*ili 5 html checkbox selectall angularjs
我试图用一个复选框选中所有复选框.但是怎么做呢?
这是我的HTML:
<input type="checkbox" ng-model="selectAll" ng-click="checkAll()" />
<!-- userlist -->
<!--<div id="scrollArea" ng-controller="ScrollController">-->
<table class="table">
<tr>
<th>User ID</th>
<th>User Name</th>
<th>Select</th>
</tr>
<tr ng-repeat="user in users | filter:search">
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td><input type="checkbox" ng-click="usersetting(user)" ng-model="user.select"></td>
<td><tt>{{user.select}}</tt><br/></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我创建了一个额外的复选框来selecet并取消选中所有复选框.
JS:
.controller('UsersCtrl', function($scope, $http){
$http.get('users.json').then(function(usersResponse) {
$scope.users = usersResponse.data;
});
$scope.checkAll = function () {
angular.forEach($scope.users, function (user) {
user.select = true;
});
};
});
Run Code Online (Sandbox Code Playgroud)
我也试过这个,但它们都不适合我:(
$scope.checkAll = function () {
angular.forEach($scope.users, function (user) {
user.select = $scope.selectAll;
});
};
Run Code Online (Sandbox Code Playgroud)
你错过了ng-controller和ng-app和的容器div angular.module.
user.select = $scope.selectAll 是正确的变种.
https://jsfiddle.net/0vb4gapj/1/
| 归档时间: |
|
| 查看次数: |
18878 次 |
| 最近记录: |