gpt4 book ai didi

javascript - 使用 AngularJs 扩展表格中的中间行

转载 作者:行者123 更新时间:2023-12-03 07:01:32 25 4
gpt4 key购买 nike

我正在创建一个支付门户,用户可以在其中为 paymentMethod numberOfIntallments 创建 paymentPlan paymentPlan 显示在带有 ng-repeat 的表格中。 numberOfIntallments 最多可达 36,我不希望用户看到有关所有分期付款的详细信息。

我想要做什么:

如果numberOfIntallments < 7,则显示所有分期付款
如果 numberOfIntallments >= 7 显示前 2 个分期 和后 2 个,并在表格中间创建一个按钮来 showAll 分期付款

我该如何解决这个问题?

当前代码:

<tr ng-repeat="model in paymentPlan.installments">
<td>{{model.dueDate | date: 'shortDate'}}</td>
<td>{{model.principal | currency:undefined:0}}</td>
<td ng-show="numberOfInstallments > 1">{{model.contractInterest | currency:undefined:0}}</td>
<td ng-show="numberOfInstallments > 1">{{model.lendingFee | currency:undefined:0}}</td>
<td ng-show="paymentMethod == 0">{{model.noticeAndPaymentFee | currency:undefined:0}}</td>
<td>{{model.installmentFee | currency:undefined:0}}</td>
<td>{{model.total | currency:undefined:0}}</td>
</tr>

最佳答案

您需要在 Controller 中进行一些计算并将结果放入范围中。然后您可以调整 ng-repeat 以获得您想要的结果。

Controller :

$scope.ShowMiddleRows = false;

if ($scope.numberOfInstallments >= 7) {
// Add the first two installments into PrefixRows[] array
for (i=0; i < 2; i++) {
$scope.PrefixRows.push($scope.paymentPlan.installments[i]);
}
// Add the lasttwo installments into SuffixRows[] array
for (i=$scope.paymentPlan.installments-2; i < scope.paymentPlan.installments; i++) {
$scope.SuffixRows.push($scope.paymentPlan.installments[i]);
}
// Add the remaining middle rows into MiddleRows[] array
for (i=2; i < $scope.paymentPlan.installments-2; i++) {
$scope.MiddleRows.push($scope.paymentPlan.installments[i]);
}
}

HTML:

<!-- this <tbody> will only show if numberOfInstallments >= 7 -->
<tbody ng-if="numberOfInstallments >= 7">

<!-- 2 PREFIX ROWS -->
<tr ng-repeat="model in PrefixRows">
<td> ... </td>
</tr>

<!-- MIDDLE ROWS or a button -->
<!-- ShowMiddleRows is a scope variable which is true or false depending on button click. Setting it to true will show the middle rows -->
<tr ng-show="!ShowMiddleRows">
<td colspan="10"><button ng-click="ShowMiddleRows = !ShowMiddleRows">Show All Installments</button></td>
</tr>
<tr ng-repeat="model in MiddleRows" ng-show="ShowMiddleRows">
<td> ... </td>
</tr>
<!-- 2 SUFFIX ROWS -->
<tr ng-repeat="model in SuffixRows">
<td> ... </td>
</tr>
</tbody>

<!-- this <tbody> will only show if numberOfInstallments < 7 -->
<tbody ng-if="numberOfInstallments < 7">
<tr ng-repeat="model in paymentPlan.installments">
<td> ... </td>
</tr>
</tbody>

关于javascript - 使用 AngularJs 扩展表格中的中间行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37031931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com