原理:在js中定义一个数组,然后给每个复选框一个点击事件,点击事件的方法参数有两个,一个是事件源$event,一个是id。点击复选框根据事件源判断是否被选中,然后进而是向这个数组增加或者删除id。
$scope.selectIds=[];//用户勾选的ID集合 ???????????//用户勾选复选框 ???????????$scope.updateSelection=function($event,id){ ???????????????if($event.target.checked){ ???????????????????$scope.selectIds.push(id);//push向集合添加元素 ???????????????}else{ ???????????????????var index= $scope.selectIds.indexOf(id);//查找值的 位置 ???????????????????$scope.selectIds.splice(index,1);//参数1:移除的位置 参数2:移除的个数 ???????????????} ???????????} ???????????//删除 ???????????$scope.dele=function(){ ???????????????if(confirm(‘确定要删除吗?‘)){ ???????????????????$http.get(‘../brand/delete.do?ids=‘+$scope.selectIds).success( ???????????????????????function(response){ ???????????????????????????if(response.success){ ???????????????????????????????$scope.reloadList();//刷新 ???????????????????????????}else{ ???????????????????????????????alert(response.message); ???????????????????????????} ???????????????????????} ???????????????????); ???????????????} ???????????}
html部分:
<td><input ?type="checkbox" ?ng-click="updateSelection($event, entity.id)"></td>
在angularJs实现批量删除
原文地址:https://www.cnblogs.com/coder-lzh/p/9074641.html