溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法

發(fā)布時(shí)間:2020-12-22 12:34:10 來(lái)源:億速云 閱讀:119 作者:小新 欄目:移動(dòng)開(kāi)發(fā)

小編給大家分享一下小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

我遇到的問(wèn)題是

小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法cdn.xitu.io/2018/5/29/163aa02a0f83cf57?imageView2/0/w/1280/h/960/format/webp/ignore-error/1">

后端給我的數(shù)據(jù)里面有每一個(gè)地址對(duì)應(yīng)的ID,比如北京:2 北京:50 東城區(qū):500

處理這個(gè)數(shù)據(jù)的時(shí)候,我根據(jù)原來(lái)大神的代碼做了一些修改,

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]) { //當(dāng)val是選擇省份的時(shí)候
                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;//地區(qū)
                    list[index].province = this.data.provinces[val[0]].id;//對(duì)應(yīng)的傳值ID
                    list[index].city = cityData[val[0]].child[0].id;//對(duì)應(yīng)的傳值ID
                    list[index].district = cityData[val[0]].child[0].child[0].id;//對(duì)應(yīng)的傳值ID
                this.setData({
                    citys: citys,
                    countys: countys,
                    values: val,
                    value: [val[0], 0, 0],
                    addrList: list
                })                    return;
                }                if (val[1] != t[1]) {//當(dāng)val是選擇城市的時(shí)候
                    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;//對(duì)應(yīng)的傳值ID
                    list[index].districtName = cityData[val[0]].child[val[1]].child[0].name;//選擇城市對(duì)應(yīng)的地區(qū)
                    list[index].district = cityData[val[0]].child[val[1]].child[0].id;//對(duì)應(yīng)的傳值ID
                    this.setData({
                        countys: countys,
                        values: val,
                        value: [val[0], val[1], 0],
                        addrList: list
                    })                    return;
                }                if (val[2] != t[2]) {//當(dāng)val是選擇地區(qū)的時(shí)候
                    list[index].districtName = this.data.countys[val[2]].name;//選擇地區(qū)
                    list[index].district = this.data.countys[val[2]].id;//對(duì)應(yīng)的傳值ID
                    this.setData({
                        county: this.data.countys[val[2]].name,
                        values: val,
                        addrList: list
                    })                    return;
                }    

            } catch(e) {
                // statements
                console.log(e);
            }
list里面是有 收貨人,電話,等等信息  但是我只操作改變數(shù)組里面地址改變的信息,

小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法

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

小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法

小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法

看完了這篇文章,相信你對(duì)小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI