[ 首页 ]

将代码更加的灵活化

calidion 发表于 • 2021年02月02日 21:23 • 共 • 122 • 次浏览
if (this.areaSearchDatas.communityCode) {
  this.areaSearchData.lev = 5;
} else if (this.areaSearchDatas.streetCode) {
  this.areaSearchData.lev = 4;
} else if (this.areaSearchDatas.areaCode) {
  this.areaSearchData.lev = 3;
} else if (this.areaSearchDatas.cityCode) {
  this.areaSearchData.lev = 2;
} else if (this.areaSearchDatas.provCode) {
  this.areaSearchData.lev = 1;
} else {
  this.areaSearchData.lev = 0;
  this.areaSearchDatas.lev = 4;
}
const codes = ['provCode', 'cityCode', 'areaCode', 'streetCode', 'communityCode'];
this.areaSearchData.lev = 0;
let found = false;
for (let i = 0; i < codes.length; i++) {
  if (this.areaSearchDatas[i]) {
    this.areaSearchData.lev = i + 1;
    found = true;
    break;
  }
}
if (!found) {
  this.areaSearchDatas.lev = 4;
}
最后编辑于 • 2021年02月02日 21:23 •  
打赏