新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法-創(chuàng)新互聯(lián)
小編給大家分享一下小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

我遇到的問(wèn)題是
后端給我的數(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里面是有 收貨人,電話(huà),等等信息 但是我只操作改變數(shù)組里面地址改變的信息,布局方面需要做一些修改的地方就是
看完了這篇文章,相信你對(duì)小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
本文名稱(chēng):小程序開(kāi)發(fā)中實(shí)現(xiàn)地址頁(yè)面三級(jí)聯(lián)動(dòng)的方法-創(chuàng)新互聯(lián)
文章路徑:http://www.dlmjj.cn/article/hcpjd.html


咨詢(xún)
建站咨詢(xún)
