Home  >  Article  >  WeChat Applet  >  How to realize three-level linkage of address page in WeChat applet development

How to realize three-level linkage of address page in WeChat applet development

php中世界最好的语言
php中世界最好的语言Original
2018-06-05 11:40:523373browse

The problem I encountered is




##The data the backend gave me contains the ID corresponding to each address, such as Beijing: 2 Beijing: 50 Dongcheng District: 500

When processing this data, I made some modifications based on the original master’s code,

<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>

layout The areas that need to be modified are

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

The use of container views in WeChat applet development

How to operate js to find the longest palindrome string in a string

The above is the detailed content of How to realize three-level linkage of address page in WeChat applet development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn