2016-02-05 52 views
0

每次被點擊切換,所有款項都得到更換新的付款。我的問題是如何維護每個點擊的特定索引的付款並顯示在各個索引處。請幫我嵌套NG-重複使用對於開放特定的索引來重複數據

這裏是我的html

  <tbody data-ng-repeat="invoice in relatedInvoices> 
       <tr> 
        <td class="td-bottom-border"> 
          {{invoice.PayableCurrencyCode}} {{invoice.PayablePaidAmount | number: 2}}<br /> 
          <small> 
           <a data-ng-click="isOpenPayablePayments[$index] = !isOpenPayablePayments[$index]; togglePayablePayments(invoice.PayableInvoiceId)">Paid</a> 
          </small> 
        </td> 
       </tr> 
       <tr data-ng-show="isOpenPayablePayments[$index]"> 
        <td> 
         <table> 
          <thead> 
           <tr> 
            <th>Transaction Id</th> 
           </tr> 
          </thead> 
          <tbody> 
           <tr data-ng-repeat="payment in payablePayments"> 
            <td>{{payment.TransactionId}}</td> 
           </tr> 
          </tbody> 
         </table> 
        </td> 
       </tr> 
      </tbody> 

這裏是我的javascript

var getPayments = function (invoiceId) { 
     paymentService.getPayments(invoiceId).then(function (paymentsResponse) { 
      return paymentsResponse.data; 
     }); 
    }; 

    $scope.togglePayablePayments = function(invoiceId) { 
     $scope.payablePayments = getPayments(invoiceId); 
    }; 
+0

你能爲此提供一個蹲位嗎?難怪你會得到新的付款,你每次都打電話給getPayments。 「維護」是什麼意思?我不清楚你想達到什麼目的。另外whereInvoices來自哪裏? –

+0

你還有這個問題嗎? –

回答

1

如果我理解正確的,你想擁有 「payablePayments」爲每張發票。

這是工作:http://plnkr.co/edit/cj3jxZ?p=info

試着這麼做

// init at beginning 
$scope.payablePayments = []; 

$scope.togglePayablePayments = function(invoiceId) { 
    $scope.payablePayments[invoiceId] = getPayments(invoiceId); 
}; 

然後

<tr data-ng-repeat="payment in payablePayments[invoice.PayableInvoiceId]"> 

否則你覆蓋對象前一發票。

+0

感謝q您的迴應。請爲我的問題http://plnkr.co/edit/omBL2czm9fRBEVIeQUyD?p=preview –

+0

http://plnkr.co/edit/cj3jxZ?p=info這是你plunker的工作叉plunkr。如果問題得到解決,請考慮將答案標記爲正確。 –