小程序
小游戏
企业微信
微信支付
扫描小程序码分享
在选择自定义的省市区之后,再次点击显示组件,下标(value)和区域值都是对的,但是页面显示的结果不对,这个错误只对最后一列,且最后一个起作用,其他的都正常,
比如这个例子,延庆区的下标是15(也就是最后一个),在进行setData的时候 下标都是对的,但是显示的内容对不上 怀柔区(是下标12)
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
有代码片段参考吗?
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
大佬可以测试一下
https://developers.weixin.qq.com/s/4gGOKtmK7W47
测试了一下你的代码,,主要是数据延时的原因,下拉到最后一个会有一个回弹动作,在回弹动作没完成前数据加载还没有开始,
你可以让用户选择完一个地址延时500ms才能点击确定
大佬,可以测试一下,只改变区的,且选择最后一个,数据都是正确的, 组件setData的值都是OK的,但是显示出来下标就对应不上 了,
按照你说的,我这边还是不行,我都等了一下才确定的
按照教程提供下,不要在原项目操作(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
这个是组件里面的部分代码
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
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)
},
getNumIndex: function (code, content) {
var itemIndex = 0
content.filter(function (itemContent, index) {
if (itemContent.code == code) {
itemIndex = index
return itemIndex
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
有代码片段参考吗?
大佬可以测试一下
https://developers.weixin.qq.com/s/4gGOKtmK7W47
测试了一下你的代码,,主要是数据延时的原因,下拉到最后一个会有一个回弹动作,在回弹动作没完成前数据加载还没有开始,
你可以让用户选择完一个地址延时500ms才能点击确定
大佬,可以测试一下,只改变区的,且选择最后一个,数据都是正确的, 组件setData的值都是OK的,但是显示出来下标就对应不上 了,
按照你说的,我这边还是不行,我都等了一下才确定的
按照教程提供下,不要在原项目操作(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
https://developers.weixin.qq.com/s/4gGOKtmK7W47
这个是组件里面的部分代码
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
},