将 SL 编号添加到角度表

发布于 2025-01-14 12:42:06 字数 510 浏览 4 评论 0原文

我有下表,其中表中是使用数组生成的:

<tbody *ngFor="let ques of questArray;let i =index">
<tr *ngif="catId == ques.categoryID">
<td> {{i}} </td>

我需要向列添加序列号

但问题是有一个 *ngif 会过滤具有不同类别的数组 因此,如果执行 {{i}},数字现在会列出来

1,2,5,6,7,11

I want to list like 1,2,3,4,5 without break.

同样在新类别中,`

我需要从 1 重新开始编号,而不是继续。

`

我可以使用另一个 *ngFor 作为序列号吗?是否可以在每个 ngif 条件下重新启动该号码

I have the following table where in the table is generated using an array:

<tbody *ngFor="let ques of questArray;let i =index">
<tr *ngif="catId == ques.categoryID">
<td> {{i}} </td>

I need to add a serial number to the column

But the problem is there is an *ngif that will filer the array with different categories
So if do {{i}} the numbers now list like

1,2,5,6,7,11

I want to list like 1,2,3,4,5 without break.

Also in the new category, `

I need to restart numbering from 1 instead of continuing.

`

Can i use another *ngFor for serial number, also is it possible to restart the number is each ngif condition

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百善笑为先 2025-01-21 12:42:06

在 questArray 的元素中添加一个新键。

例如在 ts 文件中,

let sno = 1;
for(let i=0; i < questArray; ++i){
  let ques = questArray[i];
  if(this.catId == ques.categoryID){
    questArray[i]['sno'] = sno++;
  } 
}

并在模板中使用它,如下所示,

<tbody *ngFor="let ques of questArray;let i =index">
<tr *ngif="catId == ques.categoryID">
<td> {{ques.sno}} </td>

Add a new key in element of questArray.

For example in ts file,

let sno = 1;
for(let i=0; i < questArray; ++i){
  let ques = questArray[i];
  if(this.catId == ques.categoryID){
    questArray[i]['sno'] = sno++;
  } 
}

And use that in template like below,

<tbody *ngFor="let ques of questArray;let i =index">
<tr *ngif="catId == ques.categoryID">
<td> {{ques.sno}} </td>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文