angular怎麼寫出有全選反選增刪單行單列的表格?並且能夠有一個數組是選取的項目的數據,不用jq
业精于勤,荒于嬉;行成于思,毁于随。
文件標題> 腳本> 頭>
全選/反選 {{角色.text}}
身體>
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) };
});
文件標題>
腳本>
頭>
雷雷全選/反選
{{角色.text}}
身體>
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)
};
});