3 回答
TA贡献1868条经验 获得超4个赞
扩展的话只用修改types就行了
const types = {
'CHARTS':['pie','bar','line'],
'TEXT':['normalText','multText'],
'MEDIA':['file','picture','music','video'],
}
export const typeMarry = (type) => {
for(var k in types)
if(types[k].includes(type))
return k;
}
TA贡献1836条经验 获得超5个赞
function isCharts (type) {
return ['pie','bar','line'].includes(type) ? 'CHARTS' : false
}
function isText (type) {
return ['normalText','multText'].includes(type) ? 'TEXT' : false
}
function isMedia (type) {
return ['file','picture','music','video'].includes(type) ? 'MEDIA' : false
}
const typefun = [isCharts, isText, isMedia]
export const typeMarry = (type) => {
for (let i = 0, len = typefun.length; i < len; i++) {
let cur = typefun[i](type)
if (cur) return cur
}
}
添加回答
举报