首页 > 其他 > 详细

typescript 枚举

时间:2019-09-27 16:06:53      阅读:79      评论:0      收藏:0      [点我收藏+]
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: 备件中
}]

 

typescript 枚举

原文:https://www.cnblogs.com/qgbo/p/11597537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!