gpt4 book ai didi

javascript - AngularJS 双 ng 重复

转载 作者:行者123 更新时间:2023-11-30 00:29:45 25 4
gpt4 key购买 nike

我在 Accordion 组工作,有两个 ng-repeat。外周重复从当前周到特定日期的周数。 Inner 每周有几天重复工作时间。

函数expand(week.id)是调用数据库,为变量“hour”准备数据。

我的问题是,当我单击一个 Accordion 标题以显示第 1 周的数据时,所有其他周( Accordion )的其余部分也显示相同的数据,这使得这个过程非常缓慢。

我怎样才能在我点击的标题下呈现 trs?例如,我的场景是当我点击第 1 周的标题时,只呈现第 1 周下的 trs。

谁能帮我解决这个问题?

  <accordion-group   ng-repeat="week in weeks">
<accordion-heading >
<span ng-click="expand(week.id)">{{week.firstday}}--{{week.lastday}}</span>
</accordion-heading>
<table class="table table-striped">
<thead>
<tr>
<th>Task</th>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
<th>Total</th>
</tr>
</thead>
<tbody id={{week.id}}>
<tr ng-repeat="hr in hour">

<td> <select class="form-control input-sm" ng-disabled="false"><option value="hr.task_name">{{hr.task_name}}</option></select></td>
<td><input type="number" min="0" ng-model="hr.sun" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.mon" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.tue" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.wed" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.thu" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.fri" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.sat" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><span class="form-control">{{hr.sun+hr.mon+hr.tue+hr.wed+hr.thu+hr.fri+hr.sat}}</span></td>
</tr>
</tbody>
</table>
</accordion-group>

最佳答案

hr in hour 可能使同一模型小时的所有内容,在这种情况下,如果您可以使小时成为周的属性,则需要像 hr in week.hour 那样分离模型。如果不是这样,如果小时和周相关,你可以尝试这样的 ng-init,其中小时而不是显示的小时数组是具有显示小时的数组数组:

<accordion-group   ng-repeat="week in weeks" ng-init="weekIndex = $index">
<accordion-heading >
<span ng-click="expand(week.id)">{{week.firstday}}--{{week.lastday}}</span>
</accordion-heading>
<table class="table table-striped">
<thead>
<tr>
<th>Task</th>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
<th>Total</th>
</tr>
</thead>
<tbody id={{week.id}}>
<tr ng-repeat="hr in hours[weekIndex]">

<td> <select class="form-control input-sm" ng-disabled="false"><option value="hr.task_name">{{hr.task_name}}</option></select></td>
<td><input type="number" min="0" ng-model="hr.sun" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.mon" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.tue" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.wed" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.thu" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.fri" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><input type="number" min="0" ng-model="hr.sat" class="form-control" placeholder="Hours" ng-disabled="true"></td>
<td><span class="form-control">{{hr.sun+hr.mon+hr.tue+hr.wed+hr.thu+hr.fri+hr.sat}}</span></td>
</tr>
</tbody>
</table>
</accordion-group>

关于javascript - AngularJS 双 ng 重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30066392/

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