封装枚举值转换方法

function converEnumType(value, enumName) {
    if (!value) {
        return "";
    } else {
        var fetchDcType = JSON.parse(localStorage.getItem('fetchDcType'));
        var msg = {};
        fetchDcType.map(function (item) {
            if (item.typeCode == enumName) {
                item.values.map(function (itms) {
                    var code = itms.code;
                    msg[code] = itms.name;
                });
            }
        });
        return msg[value];
    }
}

使用:

converEnumType(要转换的值,'枚举类')

猜你喜欢

转载自www.cnblogs.com/ymdzha/p/10190363.html