简体   繁体   English

如何使用angular.js选中输入复选框时如何获取表的行数据

[英]how to get row data of a table when input check box will be selected using angular.js

I need one help.I need to fetch the list of row data when check box will be select using angular.js.I am explaining my code below. 我需要一个帮助。当需要使用angular.js选中复选框时,我需要获取行数据列表。我在下面解释我的代码。

<tbody id="detailsstockid">
  <tr ng-repeat="p in viewIncompleteData">
    <td>
       {{$index+1}}<input type="checkbox" ng-model="checkboxModel.value1">   
    </td>
    <td>
       {{p.Product_name}}
    </td>
    <td>
       {{p.Discount}}
    </td>
    <td>
       {{p.Offer}}
    </td>
    <td>
       {{p.unit_cost_price}}
    </td>
    <td>
       {{p.unit_sale_price}}
    </td>
    <td>
       {{p.quantity}}
    </td>
    <td> 
    </td>
  </tr> 
</tbody>

<div style="text-align:center; padding-top:10px;" ng-show="updateButton">
   <input type="button" class="btn btn-success" ng-click="UpdateProductstockData();"  id="addProfileData" value="Add Total"/>
</div> 

When user will click on Add Total button first it will check the validation if any check box is selected or not.When any check box will select the respective row data will fetch inside the click event function.Please help me. 当用户首先单击Add Total按钮时,它将检查是否选中任何复选框。如果选中任何复选框,则相应的行数据将在click事件函数中获取。请帮助我。

<tbody id="detailsstockid">
    <tr ng-repeat="p in viewIncompleteData">
    <!-- Added new property to your scope variable viewIncompleteData -->
    <td>{{$index+1}}<input type="checkbox" ng-model="p.isChecked">  </td> 
    <td>{{p.Product_name}}</td>
    <td>{{p.Discount}}</td>
    <td>{{p.Offer}}</td>
    <td>{{p.unit_cost_price}}</td>
    <td>{{p.unit_sale_price}}</td>
    <td>{{p.quantity}}</td>
    <td> 
  </td>
    </tr>   
    </tbody>

<div style="text-align:center; padding-top:10px;" ng-show="updateButton">
<input type="button" class="btn btn-success" ng-click="UpdateProductstockData();"  id="addProfileData" value="Add Total"/>
 </div>

And now you can check your variable viewIncompleteData[i].isChecked to know which are checked. 现在,您可以检查变量viewIncompleteData[i].isChecked来知道检查了哪些。

$scope.UpdateProductstockData = function(){
    angular.forEach($scope.viewIncompleteData, function(value, index){
        if(value.isChecked){
            // this row is selected
        }
    });
}

Hope this will helps you... 希望这会帮助您...

According to me, you should take an array to track the checkbox values of respective column (like ng-model="checkboxModel.value1[$index]"). 据我说,您应该采用一个数组来跟踪相应列的复选框值(例如ng-model =“ checkboxModel.value1 [$ index]”)。 now when your ADD TOTAL button will be clicked call a function. 现在,当您单击“添加总计”按钮时,将调用一个函数。 Function should be like this: 功能应该是这样的:

function(){
 for(var i=0;i<$scope.viewIncompleteData.length;i++){
  if(checkboxModel.value1[i]==true){
   var data=$scope.viewIncompleteData[i];
  }
 }
}

Now data is your fetched row data when checkbox is checked. 现在,选中复选框后,数据就是您提取的行数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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