2014-12-04 71 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 = [];,那纳克表似乎并不正确地看到它们。

相关问题