gpt4 book ai didi

javascript - 单行的 Angular6 多个 ngFor - 如何在一个 ngFor 中传递两个值

转载 作者:搜寻专家 更新时间:2023-10-30 21:57:20 26 4
gpt4 key购买 nike

在表头中,我有动态列和搜索排序功能。但对于特定的列,我需要禁用排序功能。在表中

<thead>
<tr class="table-head">
<th *ngFor="let colName of reportColHeader; let i = index">
{{colName}}
<i [class]="sortIcons[colName]" (click)="toggleSort(colName, i)"></i>
</th>
</tr>
</thead>

constructor 中,我将值作为数组传递。不是来自服务器,它只是静态的

this.reportColHeader = ['ID', 'LABEL 1', 'LABEL 2', 'More'];

所以结果会像下面这样

<tr>
<th>ID <i></i></th>
<th>LABEL 1 <i></i></th>
<th>LABEL 2 <i></i></th>
<th>More <i></i></th>
</tr>

这里我想禁用特定列的 (排序功能)。
不仅是最后一列或第n列。我的假设是,有可能再有一个像

这样的数组
this.reportColHeaderOptions = ['true', 'true', 'false', 'false'];

通过这个值可以显示或隐藏<i></i>
那么我怎样才能把它传递给ngFor呢? .
注意:这里我不能使用索引,因为索引会改变。
但我可以按照相同的顺序关注 this.reportColHeaderthis.reportColHeaderOpions

最佳答案

为什么不能使用 index ?你可以这样做:

    <th *ngFor="let colName of reportColHeader; let i = index">
{{colName}}
<i *ngIf="reportColHeaderOpions[i]=='true'"></i>
</th>

关于javascript - 单行的 Angular6 多个 ngFor - 如何在一个 ngFor 中传递两个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53000322/

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