自定义省市区会出现下标和显示的值不对应
发布于 5 年前 作者 tsun 9323 次浏览 来自 问答

在选择自定义的省市区之后,再次点击显示组件,下标(value)和区域值都是对的,但是页面显示的结果不对,这个错误只对最后一列,且最后一个起作用,其他的都正常,

比如这个例子,延庆区的下标是15(也就是最后一个),在进行setData的时候 下标都是对的,但是显示的内容对不上 怀柔区(是下标12)

3 回复

有代码片段参考吗?

这个是组件里面的部分代码

onLoad: function (options) {

console.log(‘onLoad’, this.properties.provice, this.properties.city, this.properties.district)

var  provinces= localProvices[“provinces”]

var provinceCode,cityCode,areaCode, citys, areas,selectValue

if (this.properties.provice == ‘’ || this.properties.provice === undefined) { // 默认联动显示广东

selectValue = this.data.selectValue

provinceCode = provinces[selectValue[0]].code

citys = this.cityFilter(provinceCode)           //市

areas = this.areaFilter(citys[selectValue[1]].code)   //区

cityCode =citys[0].code

areaCode = areas[0].code

} else {

provinceCode = this.properties.provice

cityCode = this.properties.city

areaCode = this.properties.district

citys = this.cityFilter(provinceCode)           //市

areas = this.areaFilter(cityCode)   //区

// //获取下下标值

var proviceIndex = this.getNumIndex(provinceCode, provinces)

var cityIndex = this.getNumIndex(cityCode, citys)

var areaIndex = this.getNumIndex(areaCode, areas)

selectValue = [proviceIndex, cityIndex, areaIndex]

}

this.setData({

provinces: provinces,

provinceCode: provinceCode,

citys: citys,

cityCode: cityCode,

areas: areas,

selectValue: selectValue

})

console.log(‘areaIndex’, areaIndex)

console.log(‘areas’, areas)

console.log(‘selectValue’, selectValue)

this.setData({

selectValue: selectValue

})

},

getNumIndex: function (code, content) {

var itemIndex = 0

content.filter(function (itemContent, index) {

if (itemContent.code == code) {

itemIndex = index

}

})

return itemIndex

},

回到顶部