angularjs的查詢,全選,批量刪除
阿新 • • 發佈:2019-01-26
/*定義陣列*/
var data=[
{ "name":"zs",
"age":"18",
"sex":"girl",
"salary":"18000",
"check":false
},
{"name":"ls",
"age":"28",
"sex":"boy",
"salary" :"28000",
"check":false
},
{"name":"ww",
"age":"38",
"sex":"girl",
"salary":"38000",
"check":false
},
{"name":"zl",
"age":"48",
"sex":"boy",
"salary" :"48000",
"check":false
}
]
/*宣告模組*/
var myapp=angular.module("myapp",[]);
/*為模組新增控制器*/
myapp.controller("myCtrl",function ($scope) {
/*初始化陣列*/
$scope.data=data;
/*查詢方法*/
$scope.search = function () {
$scope.cz = $scope.chazhao;
}
/*刪除方法*/
$scope.shanchu=function ($index) {
$scope.data.splice($index,1);
}
/*全選*/
$scope.checkall=false;
$scope.check2=function () {
if($scope.checkall==true){
for(var i=0;i<$scope.data.length;i++){
$scope.data[i].check=true;
}
}else {
for(var i=0;i<$scope.data.length;i++){
$scope.data[i].check=false;
}
}
}
/*反選*/
var n=0;
$scope.count=function (index) {
if($scope.data[index].check==true){
n++;
}else{
n--;
}
if(n==$scope.data.length){
$scope.checkall=true;
}else{
$scope.checkall=false;
}
}
/*批量刪除*/
$scope.delAll=function () {
for(var i=0;i<$scope.data.length;i++) {
if($scope.data[i].check==true){
$scope.data.splice(i,1);
i--;
}
}
}
})