码迷,mamicode.com
首页 > 其他好文 > 详细

typescript 枚举

时间:2019-09-27 15:17:12      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:item   下拉   展示   ati   for   console   label   装饰器   static   

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 枚举

标签:item   下拉   展示   ati   for   console   label   装饰器   static   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!