javascript中使用枚举定义一个对象进行数据转换
作者:互联网
var ScheduleTypeEnum = {
IPI: {
value: 'IPI',
description: '等额本金'
},
EPI: {
value: 'EPI',
description: '等额本息'
},
IOI: {
value: 'IOI',
description: '一次还本按频率结息'
},
FPI: {
value: 'FPI',
description: '利随本清'
},
UDS: {
value: 'UDS',
description: '用户自定义还款计划'
}
};
function getDescriptionById(enums, id) {
var description = '';
for(var key in enums){
if(enums[key].value != undefined && enums[key].value == id){
description = enums[key].description;
}
}
return description;
}
console.log(getDescriptionById(ScheduleTypeEnum,'FPI'));
标签:定义,javascript,FPI,value,枚举,key,var,enums,description 来源: https://blog.51cto.com/u_3409716/2904257