这里我在表格中显示了一些数据。我的目标是当我选择一些我要删除该行的复选框时。请帮助我,我不能让它发挥作用。
Htmlcode
<div ng-controller="EmpCtrl">
<table class="table table-hover table-bordered" ng-show="GetDb.length>0">
<tr>
<th>
<input name="all" type="checkbox" ng-click="selectAllFriends()" />
</th>
<th>Id</th>
</tr>
<tr ng-repeat="ee in GetDb" ng-class="{'success' : tableSelection[$index]}">
<td>
<input name="all" type="checkbox" ng-model="ee.checked" ng-true-value="{{ee.id}}" />
</td>
<td>{{ee.id}}</td>
</div>
Controller.Js
$scope.remove = function() {
$scope.deletedIds = [];
$scope.GetDb.forEach(function (x) {
if (x.checked) {
$scope.deletedIds.push(x)
}
}
)}
答案 0 :(得分:0)
要删除,您不能保留要删除的单独副本(&#39; deletedIds&#39;),只需将其删除即可 -
$scope.remove=function(){
$scope.GetDb.forEach(function (x,index) {
if (x.checked) {
$scope.GetDb.splice(index,1);
}
}
}
答案 1 :(得分:0)
这是一个简单的解决方案 -
<div ng-controller="EmpCtrl">
<table class="table table-hover table-bordered" ng-show="GetDb.length>0">
<tr>
<th>
<input name="all" type="checkbox" ng-click="selectAllFriends()" />
</th>
<th>Id</th>
</tr>
<tr ng-repeat="ee in GetDb" ng-class="{'success' : tableSelection[$index]}">
<td>
<input name="all" type="checkbox" ng-model="ee.checked" ng-true-value="{{ee.id}}" ng-change="delete($index)"/>
</td>
<td>{{ee.id}}</td>
</div>
$scope.delete = function(index){
delete $scope.GetDb[index].checked;
delete $scope.GetDb[index].id;
};