如何在typescript中访问枚举的名称
我使用的库中有一个emum,如下所示:如何在typescript中访问枚举的名称,typescript,enums,Typescript,Enums,我使用的库中有一个emum,如下所示: /** Defines values that represent the status of a request to purchase an app or add-on. */ enum StorePurchaseStatus { /** The current user has already purchased the specified app or add-on. */ alreadyPurchased = 1, /**
/** Defines values that represent the status of a request to purchase an app or add-on. */
enum StorePurchaseStatus {
/** The current user has already purchased the specified app or add-on. */
alreadyPurchased = 1,
/** The purchase request did not succeed because of a network connectivity error. */
networkError = 3,
/** The purchase request did not succeed. */
notPurchased = 2,
/** The purchase request did not succeed because of a server error returned by the Windows Store. */
serverError = 4,
/** The purchase request succeeded. */
succeeded = 0,
}
StorePurchaseStatus[1]
我有数字值,我想打印姓名ex。我的状态为1,我想打印'alreadyPurchased'
但是,当我这样做时:
/** Defines values that represent the status of a request to purchase an app or add-on. */
enum StorePurchaseStatus {
/** The current user has already purchased the specified app or add-on. */
alreadyPurchased = 1,
/** The purchase request did not succeed because of a network connectivity error. */
networkError = 3,
/** The purchase request did not succeed. */
notPurchased = 2,
/** The purchase request did not succeed because of a server error returned by the Windows Store. */
serverError = 4,
/** The purchase request succeeded. */
succeeded = 0,
}
StorePurchaseStatus[1]
我最终没有得到定义。如果我只有该值,我如何访问字符串名?您在原始帖子中写的方式很好。你可以检查一下 以下是如何访问名称和值:
alert(StorePurchaseStatus[1]); // alreadyPurchased
alert(StorePurchaseStatus[StorePurchaseStatus[1]]);// 1
您使用的是什么版本的Typescript?在TypeScript2.7中,通过TypeScriptPlayed,我使用的是2.3.4