简体   繁体   中英

angular php bulk delete

[Solution]:Finally i did it by myself. so here is solution it takes (7 hours.)

 //Solution angularjs $scope.exampleArray = []; $scope.pushInArray = function(id) { // get the input value var inputVal = id; var array = $scope.exampleArray.push(inputVal); $scope.deleteBulk = function(){ if(confirm("Are you sure you want to delete this record?")){ $http.post('http://localhost/angular-code-crud/index.php/user/bulk_delete_user', {'id':$scope.exampleArray}).success(function(){ $scope.displayUsers(); }); } }; }; 
 <!-- Solution HTML --> <button class="btn btn-danger" ng-click="deleteBulk()" >Delete</button> <table class="table table-striped"> <thead> <tr> <th><input type="checkbox" ng-model="master" ></th> <th>Name</th> <th>Gender</th> <th>Email</th> <th>Address</th> <th>Phone</th> <th>Action</th> </tr> </thead> <tbody> </tbody> <tr ng-repeat="user in users | filter:searchUser"> <td><!-- <input type="checkbox" ng-click="deleteBulk(user.id)" ng-true-value="{{user.id}}" ng-checked="master" checklist-model="user.id" checklist-value="{{user.id}}">{{ user.id }} --> <input type="checkbox" name="arrExample" ng-model="arrInput" ng-true-value="{{user.id}}" ng-checked="master"ng-click='pushInArray(user.id)'><br> </td> <td>{{ user.name }}</td> <td>{{ user.gender }}</td> <td>{{ user.email }}</td> <td>{{ user.address }}</td> <td>{{ user.phone }}</td> <td> <button class="btn btn-primary" ng-click="updateData(user.id, user.name, user.gender, user.email, user.address, user.phone)">Edit</button> <button class="btn btn-danger" ng-click="deleteData(user.id)">Delete</button> </td> </tr> </table> 

How can i get ids of selected checkbox using angularjs? i have a table fetched using angularjs. but dont know how i transfer ids of each row which i checked using checkbox.

 $scope.deleteBulk = function($scope){ //what code should i use to get ids of checked row } 
 <button ng-click="deleteBulk()">Delete</button> <table class="table table-striped"> <thead> <tr> <th>select</th> <th>Name</th> <th>Gender</th> <th>Email</th> <th>Address</th> <th>Phone</th> <th>Action</th> </tr> </thead> <tbody> </tbody> <tr ng-repeat="user in users | filter:searchUser"> <td><input type="checkbox" checklist-model="user.roles(user.id)" checklist-value="user.id">{{ user.id }}</td> <td>{{ user.name }}</td> <td>{{ user.gender }}</td> <td>{{ user.email }}</td> <td>{{ user.address }}</td> <td>{{ user.phone }}</td> <td> <button class="btn btn-primary" ng-click="updateData(user.id, user.name, user.gender, user.email, user.address, user.phone)">Edit</button> <button class="btn btn-danger" ng-click="deleteData(user.id)">Delete</button> </td> </tr> </table> 

I'm clueless. Sorry for bad English,

 //Solution angularjs $scope.exampleArray = []; $scope.pushInArray = function(id) { // get the input value var inputVal = id; var array = $scope.exampleArray.push(inputVal); $scope.deleteBulk = function(){ if(confirm("Are you sure you want to delete this record?")){ $http.post('http://localhost/angular-code-crud/index.php/user/bulk_delete_user', {'id':$scope.exampleArray}).success(function(){ $scope.displayUsers(); }); } }; }; 
 <!-- Solution HTML --> <button class="btn btn-danger" ng-click="deleteBulk()" >Delete</button> <table class="table table-striped"> <thead> <tr> <th><input type="checkbox" ng-model="master" ></th> <th>Name</th> <th>Gender</th> <th>Email</th> <th>Address</th> <th>Phone</th> <th>Action</th> </tr> </thead> <tbody> </tbody> <tr ng-repeat="user in users | filter:searchUser"> <td><!-- <input type="checkbox" ng-click="deleteBulk(user.id)" ng-true-value="{{user.id}}" ng-checked="master" checklist-model="user.id" checklist-value="{{user.id}}">{{ user.id }} --> <input type="checkbox" name="arrExample" ng-model="arrInput" ng-true-value="{{user.id}}" ng-checked="master"ng-click='pushInArray(user.id)'><br> </td> <td>{{ user.name }}</td> <td>{{ user.gender }}</td> <td>{{ user.email }}</td> <td>{{ user.address }}</td> <td>{{ user.phone }}</td> <td> <button class="btn btn-primary" ng-click="updateData(user.id, user.name, user.gender, user.email, user.address, user.phone)">Edit</button> <button class="btn btn-danger" ng-click="deleteData(user.id)">Delete</button> </td> </tr> </table> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM