
获得徽章 0
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇文章
赞了这篇沸点
使用策略模式,如何精简下面的代码?
let tempSortArr=[];
res.data.forEach(item=>{
if(item.strip_line_name.includes('物业费')){
tempSortArr[0]=item
}
if(item.strip_line_name.includes('水电费')){
tempSortArr[1]=item
}
if(item.strip_line_name.includes('工程费')){
tempSortArr[2]=item
}
if(item.strip_line_name.includes('案场费')){
tempSortArr[3]=item
}
if(item.strip_line_name.includes('其他费')){
tempSortArr[4]=item
}
})
console.log(tempSortArr)
let tempSortArr=[];
res.data.forEach(item=>{
if(item.strip_line_name.includes('物业费')){
tempSortArr[0]=item
}
if(item.strip_line_name.includes('水电费')){
tempSortArr[1]=item
}
if(item.strip_line_name.includes('工程费')){
tempSortArr[2]=item
}
if(item.strip_line_name.includes('案场费')){
tempSortArr[3]=item
}
if(item.strip_line_name.includes('其他费')){
tempSortArr[4]=item
}
})
console.log(tempSortArr)
展开
7
4
赞了这篇文章
赞了这篇文章