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

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

php中世界最好的语言
发布: 2018-06-05 11:40:52
原创
3511 人浏览过

我遇到的问题是




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

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

<code class="hljs bash" style="box-sizing: border-box; outline: 0px; display: block; padding: 0px; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; background-color: rgb(246, 248, 250); border-radius: 4px; overflow-x: auto; word-wrap: normal; word-break: break-all;"><span style="font-size: 14px;"><span class="hljs-built_in" style="font-size: 14px; box-sizing: border-box; outline: 0px; color: rgb(79, 79, 79); word-break: break-all;">let</span> val = e.detail.value,

            t = this.data.values,

            cityData = this.data.cityData,

            index = this.data.id,

            list = this.data.addrList;

            list[index].area = <span class="hljs-literal" style="font-size: 14px; box-sizing: border-box; outline: 0px; color: rgb(0, 102, 102); word-break: break-all;">true</span>;

            try {                <span class="hljs-keyword" style="font-size: 14px; box-sizing: border-box; outline: 0px; color: rgb(0, 0, 136); word-break: break-all;">if</span> (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

                })                    <span class="hljs-built_in" style="font-size: 14px; box-sizing: border-box; outline: 0px; color: rgb(79, 79, 79); word-break: break-all;">return</span>;

                }                <span class="hljs-keyword" style="font-size: 14px; box-sizing: border-box; outline: 0px; color: rgb(0, 0, 136); word-break: break-all;">if</span> (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

                    })                    <span class="hljs-built_in" style="font-size: 14px; box-sizing: border-box; outline: 0px; color: rgb(79, 79, 79); word-break: break-all;">return</span>;

                }                <span class="hljs-keyword" style="font-size: 14px; box-sizing: border-box; outline: 0px; color: rgb(0, 0, 136); word-break: break-all;">if</span> (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

                    })                    <span class="hljs-built_in" style="font-size: 14px; box-sizing: border-box; outline: 0px; color: rgb(79, 79, 79); word-break: break-all;">return</span>;

                }   

 

            } catch(e) {

                // statements

                console.log(e);

            }

list里面是有 收货人,电话,等等信息  但是我只操作改变数组里面地址改变的信息,</span></code>

登录后复制

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

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

推荐阅读:

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

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

以上是微信小程序开发中怎样实现地址页面三级联动的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板