Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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
如何将typescript枚举值转换为字符串_Typescript - Fatal编程技术网

如何将typescript枚举值转换为字符串

如何将typescript枚举值转换为字符串,typescript,Typescript,我的脚本中有一个枚举。我需要将枚举的值转换为字符串,以便将其传递给api端点。我该怎么做?谢谢 enum RecordStatus { CancelledClosed = 102830004, Completed = 102830003, InProgress = 102830002, ShoppingCart = 102830005, Submitted = 102830001, Unordered = 102830000 } 例如: var

我的脚本中有一个枚举。我需要将枚举的值转换为字符串,以便将其传递给api端点。我该怎么做?谢谢

enum RecordStatus {
    CancelledClosed = 102830004,
    Completed = 102830003,
    InProgress = 102830002,
    ShoppingCart = 102830005,
    Submitted = 102830001,
    Unordered = 102830000
}
例如:

var submittedStrValue = RecordStatus.Submitted // I want to get "10283001" (note the string value rather than the int value. 

你可以使用
RecordStatus.Submitted.toString()

那么,你是在问如何将一个数字转换成一个字符串?可能是“Ok”的重复,我认为这需要执行类似于RecordStatus[RecordStatus.Submitted]的操作。@JeffreyJuarez如果你想获得字符串
Submitted
。请看,您也可以始终使用字符串枚举,特别是如果您始终希望使用字符串值,并且要显式地为每个枚举分配一个值。