资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

小程序开发中实现地址页面三级联动的方法-创新互联

小编给大家分享一下小程序开发中实现地址页面三级联动的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

创新互联公司从2013年创立,是专业互联网技术服务公司,拥有项目成都网站制作、做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元樊城做网站,已为上家服务,为樊城各地企业和个人服务,联系电话:028-86922220

我遇到的问题是

后端给我的数据里面有每一个地址对应的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里面是有 收货人,电话,等等信息  但是我只操作改变数组里面地址改变的信息,

小程序开发中实现地址页面三级联动的方法

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

小程序开发中实现地址页面三级联动的方法

小程序开发中实现地址页面三级联动的方法

看完了这篇文章,相信你对小程序开发中实现地址页面三级联动的方法有了一定的了解,想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


本文名称:小程序开发中实现地址页面三级联动的方法-创新互联
本文来源:http://cdkjz.cn/article/hcpjd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220