1.获取到当前的code
type: this.getType(list.stock.type)
2:循环判断
getType(code){
let txt="";
let info= this.stockTypeList.filter(item=>item.code==code);
console.log(info)
if(info.length>0){
txt=info[0].name;
}
return txt; //返回对应的字段
},
本文介绍了一种使用JavaScript进行类型判断的方法,通过循环遍历和数组过滤实现对特定类型的精确匹配,提高了代码的灵活性和可读性。
1.获取到当前的code
type: this.getType(list.stock.type)
2:循环判断
getType(code){
let txt="";
let info= this.stockTypeList.filter(item=>item.code==code);
console.log(info)
if(info.length>0){
txt=info[0].name;
}
return txt; //返回对应的字段
},
6238

被折叠的 条评论
为什么被折叠?