Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 角度:在同一模板中重置索引值_Html_Angular_Html Table - Fatal编程技术网

Html 角度:在同一模板中重置索引值

Html 角度:在同一模板中重置索引值,html,angular,html-table,Html,Angular,Html Table,我有一个由3个表组成的模板,这些表与父表具有相同的JSON,如下所示 <tbody> <ng-container *ngFor="let row of reportingData.RecommendationData; let i=index"> <tr *ngIf="row.swRecommendations"> <td>{{i+1}}</td> <td&g

我有一个由3个表组成的模板,这些表与父表具有相同的JSON,如下所示

<tbody>
    <ng-container *ngFor="let row of reportingData.RecommendationData; let i=index">
        <tr *ngIf="row.swRecommendations">
            <td>{{i+1}}</td>
            <td> {{row.swRecommendations.deviceID}}</td>
        </tr>
     </ng-container>
</tbody>

{{i+1}}
{{row.sw.deviceID}
另一个表体

<tbody>
    <ng-container *ngFor="let row of reportingData.RecommendationData; let j=index">
        <tr *ngIf="row.licenseRecommendations">
            <td>{{j+1}}</td>
            <td> {{row.licenseRecommendations.deviceID}}</td>
        </tr>
     </ng-container>
</tbody>

{{j+1}}
{{row.licenseRecommensions.deviceID}

所有这些表都在同一个模板中。我将索引值分配给不同的变量(I&j),但增量正在发生,即,如果第一个表有5行,则第二个表从6开始,而不是从1开始。如何修复此问题?

我测试了您的代码,索引从0开始。 请检查我的代码

Component.html

<h1>First Table</h1>
<table>
    <tr>
        <th>Id</th>
        <th>Name</th>
    </tr>
    <ng-container>
        <tr *ngFor="let a of array;let i = index">
            <th>{{i + 1}}</th>
            <th>{{a.name}}</th>
        </tr>
    </ng-container>
</table>
<h1>Second Table</h1>
<table>
    <tr>
        <th>Id</th>
        <th>Name</th>
    </tr>
    <ng-container>
        <tr *ngFor="let a of array;let j = index">
            <th>{{j + 1}}</th>
            <th>{{a.name}}</th>
        </tr>
    </ng-container>
</table>

H最近遇到了同样的问题,因为我们正在对它进行索引并将其递增,所以这个问题的解决方案就像在ts中过滤数据一样

    this.a= this.reportingData.filter(x => x.swRecommendations);
    this.b= this.reportingData.filter(x => x.licenseRecommendations);
    <tr *ngFor="let row of a"> <tr *ngFor="let row of b">,
this.a=this.reportingData.filter(x=>x.sw);
this.b=this.reportingData.filter(x=>x.licenseRecommensions);
,

然后删除if条件并像下面这样在HTML中迭代数据,根据您在ts中的考虑编辑所需的reportingData行

也许您可以将reportingData.RecommendationData拆分为两个数组?或者您可以有一个计算索引的函数,如:
{getIndex(row)}
在函数中,您可以使用逻辑来确定它是否应该具有重置索引值。您将函数放在组件中这是不可能的,如果您正在运行您在问题中询问的代码,那么它应该从0开始每个索引。奇怪的是,在我的代码中,它取第一个表在第二个表中的最后一个索引
    this.a= this.reportingData.filter(x => x.swRecommendations);
    this.b= this.reportingData.filter(x => x.licenseRecommendations);
    <tr *ngFor="let row of a"> <tr *ngFor="let row of b">,