直接上代码:
结构:
<table id="" class="table table-bordered hover text-center newsClassifyTable" cellspacing="0" width="100%" role="grid" >
<thead>
<tr role="row">
<th class="text-center">
<label class="i-checks m-b-none">
<input type="checkbox" ng-model="all" ng-change="allSelect()"><i></i>
</label>
</th>
<th>底价货号</th>
<th>供应商</th>
<th>仓库</th>
</tr>
</thead>
<tbody>
<tr ng-show="floorPriceTable.length == 0">
<td colspan="21">无数据</td>
</tr>
<tr ng-repeat="list in floorPriceTable" ng-show="floorPriceTable.length > 0">
<td>
<label class="i-checks m-b-none">
<input type="checkbox" ng-model="list.selectedStatus" ng-change="listSelect(list.id)"><i></i>
</label>
</td>
<td>{{list.id}}</td>
<td>{{list.supplierName}}</td>
<td>{{list.storeName}}</td>
</tr>
</tbody>
</table>
逻辑
//勾选
$scope.allSelect = function () {
if($scope.all){
$scope.floorPriceTable.forEach(function (value) {
value.selectedStatus = true;
});
}else{
$scope.floorPriceTable.forEach(function (value) {
value.selectedStatus = false;
});
}
};
$scope.listSelect = function (param) {
if(param.selectedStatus){
$scope.all = true;
$scope.floorPriceTable.forEach(function (value) {
if(!value.selectedStatus){
$scope.all = false
}
});
}else{
$scope.all = false
}
}
//勾选了哪些货品
$scope.selectResult = function(){
console.log($scope.floorPriceTable)
var idList = [];
$scope.floorPriceTable.forEach(function(value){
if(value.selectedStatus){
idList.push(value.id);
}
})
console.log(idList)
return idList
}