我想实现选择菜单,该菜单使用枚举数据来显示数据和基于所选字符串的保存的数字:
export enum MerchantStateType {
being_set_up = 1,
live_for_processing = 2,
trading_suspended = 3,
account_suspended = 4,
}
export const MerchantStateType2LabelMapping = {
[MerchantStateType.being_set_up]: "Being set up",
[MerchantStateType.live_for_processing]: "Live for processing",
[MerchantStateType.trading_suspended]: "Trading suspended",
[MerchantStateType.account_suspended]: "Account suspended",
}
HTML:
<div class="form-group state_raw">
<label for="state_raw">State</label>
<select class="custom-select" name="state_raw" [(ngModel)]="merchant.state_raw" id="state_raw" required>
<!--<option selected></option>-->
<option [value]="stateType" *ngFor="let stateType of stateTypes">{{ MerchantStateType2LabelMapping[stateType] }}</option>
</select>
</div>
页面加载时merchant.state_raw
加载了值,例如2
如何将值从值转换为字符串并进入选择菜单,然后再次将其另存为数字?