angular中表格的全选,单选的互相控制

本文介绍如何在Angular应用中实现表格的全选和单选功能,并实现它们之间的相互控制。通过示例代码展示具体的逻辑操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直接上代码:
结构:

 <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 
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值