在angularJs實現批量刪除


原理:在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>
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM