gpt4 book ai didi

javascript - 如何循环枚举值以在单选按钮中显示?

转载 作者:IT王子 更新时间:2023-10-29 02:40:18 24 4
gpt4 key购买 nike

<分区>

在 TypeScript 中遍历枚举文字的正确方法是什么?

(我目前使用的是 TypeScript 1.8.1。)

我有以下枚举:

export enum MotifIntervention {
Intrusion,
Identification,
AbsenceTest,
Autre
}

export class InterventionDetails implements OnInit
{
constructor(private interService: InterventionService)
{
let i:number = 0;
for (let motif in MotifIntervention) {
console.log(motif);
}
}

显示的结果是一个列表

0
1
2
3
Intrusion,
Identification,
AbsenceTest,
Autre

我确实希望循环中只有四次迭代,因为枚举中只有四个元素。我不想让 0 1 2 和 3 看起来像是枚举的索引号。

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