收藏
回答

自定义省市区会出现下标和显示的值不对应

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


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

回答关注问题邀请回答
收藏

3 个回答

  • ==
    ==
    2018-12-07

    有代码片段参考吗?

    2018-12-07
    有用 1
    回复 8
    • 寒风回归
      寒风回归
      2018-12-07

      大佬可以测试一下

      https://developers.weixin.qq.com/s/4gGOKtmK7W47

      2018-12-07
      回复
    • ==
      ==
      2018-12-07回复寒风回归

      测试了一下你的代码,,主要是数据延时的原因,下拉到最后一个会有一个回弹动作,在回弹动作没完成前数据加载还没有开始,

      2018-12-07
      回复
    • ==
      ==
      2018-12-07回复寒风回归

      你可以让用户选择完一个地址延时500ms才能点击确定

      2018-12-07
      回复
    • 寒风回归
      寒风回归
      2018-12-07回复==

      大佬,可以测试一下,只改变区的,且选择最后一个,数据都是正确的, 组件setData的值都是OK的,但是显示出来下标就对应不上 了,

      2018-12-07
      回复
    • 寒风回归
      寒风回归
      2018-12-07回复==

      按照你说的,我这边还是不行,我都等了一下才确定的


      2018-12-07
      回复
    查看更多(3)
  • 是小白啊
    是小白啊
    2018-12-07

    按照教程提供下,不要在原项目操作(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2018-12-07
    有用
    回复 1
  • 寒风回归
    寒风回归
    2018-12-07

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


    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

    },


    2018-12-07
    有用
    回复
登录 后发表内容