当前位置:首页站长学院后端开发微信小程序开发中怎样实现地址页面三级联动
企业营销,就选知企PROSAAS

微信小程序开发中怎样实现地址页面三级联动

我遇到的问题是

微信小程序开发中怎样实现地址页面三级联动

后端给我的数据里面有每一个地址对应的ID,比如北京:2 北京:50 东城区:500

处理这个数据的时候,我根据原来大神的代码做了一些修改,

let val = e.detail.value,
            t = this.data.values,
            cityData = this.data.cityData,
            index = this.data.id,
            list = this.data.addrList;
            list[index].area = true;
            try {                if (val[0] != t[0]) { //当val是选择省份的时候
                const citys = [];
                const countys = [];
                    cityData[val[0]].child.map(item => citys.push({name:item.name,id:item.id}));
                    cityData[val[0]].child[0].child.map(item => countys.push({name:item.name,id:item.id}));
                    list[index].provinceName = this.data.provinces[val[0]].name;//省份
                    list[index].cityName = cityData[val[0]].child[0].name;//城市
                    list[index].districtName = cityData[val[0]].child[0].child[0].name;//地区
                    list[index].province = this.data.provinces[val[0]].id;//对应的传值ID
                    list[index].city = cityData[val[0]].child[0].id;//对应的传值ID
                    list[index].district = cityData[val[0]].child[0].child[0].id;//对应的传值ID
                this.setData({
                    citys: citys,
                    countys: countys,
                    values: val,
                    value: [val[0], 0, 0],
                    addrList: list
                })                    return;
                }                if (val[1] != t[1]) {//当val是选择城市的时候
                    const countys = [];
                    cityData[val[0]].child[val[1]].child.map(item => countys.push({name:item.name,id:item.id}));
                    list[index].cityName = this.data.citys[val[1]].name;// 选择城市
                    list[index].city = this.data.citys[val[1]].id;//对应的传值ID
                    list[index].districtName = cityData[val[0]].child[val[1]].child[0].name;//选择城市对应的地区
                    list[index].district = cityData[val[0]].child[val[1]].child[0].id;//对应的传值ID
                    this.setData({
                        countys: countys,
                        values: val,
                        value: [val[0], val[1], 0],
                        addrList: list
                    })                    return;
                }                if (val[2] != t[2]) {//当val是选择地区的时候
                    list[index].districtName = this.data.countys[val[2]].name;//选择地区
                    list[index].district = this.data.countys[val[2]].id;//对应的传值ID
                    this.setData({
                        county: this.data.countys[val[2]].name,
                        values: val,
                        addrList: list
                    })                    return;
                }    

            } catch(e) {
                // statements
                console.log(e);
            }
list里面是有 收货人,电话,等等信息  但是我只操作改变数组里面地址改变的信息,

微信小程序开发中怎样实现地址页面三级联动

布局方面需要做一些修改的地方就是

微信小程序开发中怎样实现地址页面三级联动微信小程序开发中怎样实现地址页面三级联动

相信看了本文案例你已经掌握了方法,更多精彩请关注知企PROSAAS其它相关文章!

推荐阅读:

微信小程序开发容器视图的使用

如何操作js找出字符串中最长回文串

以上就是微信小程序开发中怎样实现地址页面三级联动的详细内容,更多请关注知企PROSAAS其它相关文章!

温馨提示:

文章标题:微信小程序开发中怎样实现地址页面三级联动

文章链接:https://ceshi.prosaas.cn/17500.html

更新时间:2018年06月05日

声明: 本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:973664285@qq.com我们将第一时间处理! 资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。 所有资源仅限于参考和学习,版权归原作者所有,更多请阅读知企PROSAAS协议

给TA打赏
共{{data.count}}人
人已打赏
后端开发

微信小程序开发中Android请求失败如何处理

2018-6-5 11:36:44

后端开发

微信小程序开发中怎样实现Android环境下的横向滚动

2018-6-5 11:43:02

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索