2014-12-04 74 views
2

我有一個計算函數,當被調用是要採取幾個值,並用它們來填補結果ng表。一切工作正常,除了該表應分頁到一次只顯示10個值。相反,所有的值都會一次顯示出來。在頁面底部出現下一個和後退按鈕,用於切換表格的值。以下是我正在使用的angularjs代碼。我不確定問題出在哪裏。我的ng表顯示所有它的值時,它應該只顯示10

$scope.tableParams = new ngTableParams({ 
     page: 1,  //show first page 
     count: 10  //conunt per page 
    },{ 
     total: $scope.subsidyPaymentScheduleTable.length, 
      getData: function($defer, params){ 
       $defer.resolve($scope.subsidyPaymentScheduleTable.slice((params.page() - 1) * params.count(), params.page() * params.count())); 
      } 

    }); 

    //populates the Subsidy table 
    $scope.populateSubsidyTable = function(monthlySubsidyRedAm, startingSubsidy, monthsOnSubsidy) 
    { 
     var currentSubsidy = 0; 
     var currentDate = $scope.startingDate; 
     var subsidyDate = new Date(); 
     var monthsLeft = monthsOnSubsidy 
     $scope.subsidyPaymentScheduleTable = []; 
     var subsidyPaymentScheduleArray = []; 

     if(startingSubsidy > 1) 
     { 
      currentSubsidy = startingSubsidy; 
     } 

     if(monthlySubsidyRedAm <=0) 
     { 
      totalAmount = currentSubsidy * 6; 
     } 
     else 
     { 
      //the first month 

      $scope.subsidyPaymentScheduleTable.push({ 
        subsidyDate: currentDate, 
        subsidyAmount: currentSubsidy 
      }); 

      $scope.totalSubsidy = $scope.totalSubsidy + currentSubsidy; 

      //the first 5 months after the first 
      for(i=2; i <= 6; i++) 
      { 
       currentDate = moment(currentDate).add(1,'months').format("MM/DD/YYYY"); 


       $scope.subsidyPaymentScheduleTable.push({ 
        subsidyDate: currentDate, 
        subsidyAmount: currentSubsidy 
       }); 

       monthsLeft = monthsOnSubsidy - 6; 

       $scope.totalSubsidy = $scope.totalSubsidy + currentSubsidy; 

      } 
      //the rest of the subsidies 
      while(monthsOnSubsidy > 0) 
      { 
       if((currentSubsidy - monthlySubsidyRedAm) > 1) 
       { 
         currentSubsidy = currentSubsidy - monthlySubsidyRedAm; 

         currentDate = moment(currentDate).add(1,'months').format("MM/DD/YYYY"); 

         $scope.subsidyPaymentScheduleTable.push({ 
          subsidyDate: currentDate, 
          subsidyAmount: currentSubsidy 
         }); 

         $scope.totalSubsidy = $scope.totalSubsidy + currentSubsidy; 

         monthsLeft--; 
       } 
       else 
       { 
        break; 
       } 
      } 

      //reload subsidy table 
      $scope.tableParams.total($scope.subsidyPaymentScheduleTable.length); 
      $scope.tableParams.reload(); 
     } 
    } 

這是HTML代碼

<table ng-table="tableParams" class="table subsidyPaymentScheduleTable"> 
     <tr data-ng-repeat="subsidy in subsidyPaymentScheduleTable" class="clickableRow"> 
      <td data-title="'Date'"> 
       {{subsidy.subsidyDate}} 
      </td> 
      <td data-title="'Amount'"> 
       {{subsidy.subsidyAmount | currency:"$"}} 
      </td> 
     </tr> 
    </table> 

回答

0

我發現,當我$scope下聲明變量,而不是作爲var data = [];,那納克表似乎並不正確地看到它們。

相關問題