typescript 枚举

class  Sex {
   static Male={
        Value:0,
        Label:'',
        Description:''
    }
    static FeMale={
        Value:1,
        Label:'',
        Description:''
    }
}
console.log(Sex.Male.Value);

枚举上可以加装饰器来像C# 那样获取描述吗?可以暂时用这种类来代替枚举。

C# 写下面的代码可以生成枚举列表:

public static List<KeyValuePair<Enum, string>> GetList(this Type T)
        {
            var result = new List<KeyValuePair<Enum, string>>();
            foreach (Enum item in Enum.GetValues(T))
            {
                result.Add(new KeyValuePair<Enum, string>(item, item.GetDescription()));
            }

            return result;
        }

会生成这样的东西:这个用来展示前端的下拉列表。至于枚举可以拷到前端来。

this.statusEnumList = [
{
key: 2,
value: '审批中'
},
{
key: 4,
value: '备件中'
}]

猜你喜欢

转载自www.cnblogs.com/qgbo/p/11597537.html