angular怎么写出带全选反选增删单行单列的表格?并且能够有一个数组是选中的项的数据,不用jq
业精于勤,荒于嬉;行成于思,毁于随。
<html lang="en" >
文档标题> <脚本 src="angular.js"></脚本> </头>
<input type="checkbox" ng-checked="user.roles.length == Roles.length" ng-click="checkAll()" >全选/反选 {{角色.text}}
身体>
</html>
var app = angular.module("app", ["checklist-model"]);
app.controller('Ctrl', function($scope) { $scope.roles = [ {id: 1, text: '客人'}, {id: 2, text: '用户'}, {id: 3, text: '客户'}, {id: 4, text: 'admin'} ]; $scope.ids = []; //选择结果集合 $scope.user = { 角色:[] };
$scope.checkAll = function() { console.log($scope.user.roles.length == $scope.roles.length) if($scope.user.roles.length == $scope.roles.length){ $scope.user.roles = []; $scope.ids = []; }其他{ $scope.user.roles = angular.copy($scope.roles); $scope.ids = []; }
}; $scope.del =函数(){ for(x in $scope.user.roles){ $scope.ids.push($scope.user.roles[x].id); }
console.log($scope.ids) };
});
<html lang="en" >
文档标题>
<脚本 src="angular.js"></脚本>
</头>
雷雷<input type="checkbox" ng-checked="user.roles.length == Roles.length" ng-click="checkAll()" >全选/反选
{{角色.text}}
身体>
</html>
var app = angular.module("app", ["checklist-model"]);
app.controller('Ctrl', function($scope) {
$scope.roles = [
{id: 1, text: '客人'},
{id: 2, text: '用户'},
{id: 3, text: '客户'},
{id: 4, text: 'admin'}
];
$scope.ids = [];
//选择结果集合
$scope.user = {
角色:[]
};
$scope.checkAll = function() {
console.log($scope.user.roles.length == $scope.roles.length)
if($scope.user.roles.length == $scope.roles.length){
$scope.user.roles = [];
$scope.ids = [];
}其他{
$scope.user.roles = angular.copy($scope.roles);
$scope.ids = [];
}
};
$scope.del =函数(){
for(x in $scope.user.roles){
$scope.ids.push($scope.user.roles[x].id);
}
console.log($scope.ids)
};
});