2017-06-06 65 views
0
  1. 朋友你好獲取打印,我在角js.I新需要幫助的打印分配給每一行按鍵的點擊每個 行的數據。以下是我的 代碼。在每一行上的點擊,相應行的數據應在角JS

    HTML代碼:

    • 列表項

    在這裏輸入的代碼

    <div class="jumbotron"> 
        <table border='1'> 
        <tr ng-show="reports.length!=0" ng-repeat="report in reports"> 
    
         <td>{{report.first_name}}</td> 
         <td>{{report.emp_id}}</td> 
         <td>{{report.month_calendar_days}}</td> 
         <td>{{report.pay_days}}</td> 
         <td>{{report.paid_days}}</td> 
         <td> 5" ng-repeat="key in noAlphabetSortPlease(report)" style="padding-left:10px;">{{report[key]}}</td> 
         <td><button ng-click="PrintRow()">Print Row</button></td> 
        </tr> 
    
        </table> 
    </div> </div> 
    

    控制器代碼:

    angular.module( '應用',[])

    .controller('mainController', ['$scope', '$filter', function($scope, 
    $filter) { 
        $scope.noAlphabetSortPlease = function(obj){ 
         return Object.keys(obj); 
        } 
        $scope.reports = [{"emp_id":"10001","first_name":"siva","status":1,"month_calendar_days":29,"pay_days":29,"paid_days":21,"salary_head_value1":0,"salary_head_value2":7550,"salary_head_value3":1600,"salary_head_value4":1800,"salary_head_value5":345,"salary_head_value6":6400,"salary_head_value7":5000,"salary_head_value8":31955,"salary_head_value9":1250,"salary_head_value10":12000,"salary_head_value11":6000,"salary_head_value12":47900,"salary_head_value13":15945,"salary_head_value14":4000,"salary_head_value15":2400}, 
    {"emp_id":"10002","first_name":"naren","status":1,"month_calendar_days":29,"pay_days":29,"paid_days":21,"salary_head_value1":15501,"salary_head_value2":7551,"salary_head_value3":1601,"salary_head_value4":1801,"salary_head_value5":346,"salary_head_value6":6401,"salary_head_value7":5001,"salary_head_value8":31957,"salary_head_value9":1251,"salary_head_value10":12001,"salary_head_value11":6001,"salary_head_value12":47907,"salary_head_value13":15950,"salary_head_value14":4001,"salary_head_value15":2401}, 
    {"emp_id":"10003","first_name":"Bhaki","status":1,"month_calendar_days":29,"pay_days":29,"paid_days":21,"salary_head_value1":15502,"salary_head_value2":7552,"salary_head_value3":1602,"salary_head_value4":1802,"salary_head_value5":347,"salary_head_value6":6402,"salary_head_value7":5002,"salary_head_value8":31959,"salary_head_value9":1252,"salary_head_value10":12002,"salary_head_value11":6002,"salary_head_value12":47914,"salary_head_value13":15955,"salary_head_value14":4002,"salary_head_value15":2402}]; 
    
    
        $scope.PrintRow=function($index){   window.print(); 
          } }]); </script> 
    
+0

您不需要ng-show,並且在ng-click上方的行看起來像缺少某些東西。 – rrd

+0

嘗試用ng-repeat-start + ng-repeat-end – Plankton

+0

這並不重要..我在每行添加了按鈕。當用戶單擊任意一行時,相應的行應該打印。 –

回答

2

將相應的對象傳遞給函數調用並覆蓋報告變量。

<tr ng-show="reports.length!=0" ng-repeat="report in reports"> 

     <td>{{report.first_name}}</td> 
     <td>{{report.emp_id}}</td> 
     <td>{{report.month_calendar_days}}</td> 
     <td>{{report.pay_days}}</td> 
     <td>{{report.paid_days}}</td> 
     <td> 5" ng-repeat="key in noAlphabetSortPlease(report)" style="padding-left:10px;">{{report[key]}}</td> 
     <td><button ng-click="PrintRow(report)">Print Row</button></td> 
    </tr> 


    $scope.PrintRow=function(obj){ 
    $scope.reports=[]; 
    $scope.reports.push(obj); 
      } 

,或者如果你希望所有的數據依然存在,要打印低於新的每一行的相應數據table.Then你可以做這樣的事情

<tr ng-show="reports.length!=0" ng-repeat="report in reports"> 

     <td>{{report.first_name}}</td> 
     <td>{{report.emp_id}}</td> 
     <td>{{report.month_calendar_days}}</td> 
     <td>{{report.pay_days}}</td> 
     <td>{{report.paid_days}}</td> 
     <td> 5" ng-repeat="key in noAlphabetSortPlease(report)" style="padding-left:10px;">{{report[key]}}</td> 
     <td><button ng-click="PrintRow(report)">Print Row</button></td> 
    </tr> 

{{newArray}}

$scope.newArray=[]; 
    $scope.PrintRow=function(obj){ 
    $scope.newArray.push(obj); 
      } 

根據您的意願設置新數組。

<tr ng-show="reports.length!=0" ng-repeat="report in newArray"> 

     <td>{{report.first_name}}</td> 
     <td>{{report.emp_id}}</td> 
     <td>{{report.month_calendar_days}}</td> 
     <td>{{report.pay_days}}</td> 
     <td>{{report.paid_days}}</td> 
     <td> 5" ng-repeat="key in noAlphabetSortPlease(report)" style="padding-left:10px;">{{report[key]}}</td> 
     <td><button ng-click="PrintRow(report)">Print Row</button></td> 
    </tr> 
+0

很多謝謝Vivz .... –

+0

這是你在找什麼? – Vivz

+0

是的..我在找這些東西。請多多謝謝 –

相關問題