因业务需要,前台使用picker组件选择地市,后台录入数据的时候,需要对应的地市数据,否则前后台数据不一致,导致部分数据出不来
bindRegionChange(e) {
this.openCity()
let cityName = e.detail.value[1]
this.data.cityList.map((item) => {
if (item.townName === cityName.substring(0, 2)) {
console.log(item.townId)
this.setData({
schoolTownId: item.townId,
schoolType: ‘HIGH_SCHOOL’,
schoolName: ‘’,
changeColor: true
})
}
})
this.setData({
region: cityName.substring(0, cityName.length - 1)
})
},
//选择高中后确定
saveCity() {
this.setData({
schoolName: this.data.region + ‘-高中生’,
isSchool: false
})
}
this.dataList是一个接口返回的城市数据,使用townName跟官方的picker的townName匹配。拿到townId即可