我有一个asp.net核心项目,我正在使用react。
C实体:

public class Waybill: IEntity
{
    public int Id { get; set; }

    public WayBillType WayBillType { get; set; }
}

public enum WayBillType
{
    Moving = 1,
    Incoming = 2,
    Disposal  = 3
}

和类型脚本实体:
export class Waybill
{
    id: number;
    wayBillType: WayBillType;
}

enum WayBillType
{
    Moving = 1,
    Incoming = 2,
    Outgoing = 3
}

如何在react组件中使字符串“移动”而不是“1”?

最佳答案

您可以使用JsonConverter属性并将StringEnumConverterNewtonsoft.Json.Converters传递给它:

[JsonConverter(typeof(StringEnumConverter))]
public enum WayBillType
{
    Moving = 1,
    Incoming = 2,
    Disposal = 3
}

09-17 08:45