最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序手動(dòng)添加收貨地址省市區(qū)聯(lián)動(dòng)

 更新時(shí)間:2020年05月18日 17:30:06   作者:月亮上的垂耳朵  
這篇文章主要為大家詳細(xì)介紹了微信小程序手動(dòng)添加收貨地址省市區(qū)聯(lián)動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序手動(dòng)添加收貨地址省市區(qū)聯(lián)動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下

先看效果圖

html部分

用小程序的piceker-view 嵌入頁面的滾動(dòng)選擇器

<picker-view indicator-style="height: 50px;" style="width:100%; height: 400rpx;" bindchange="bindChange">
 <picker-view-column class="selectItem">
 <view class="tooth" wx:for="{{province}}" wx:key="this">{{item.name}}</view>
 </picker-view-column>
 <picker-view-column class="selectItem">
 <view class="tooth" wx:for="{{city}}" wx:key="this">{{item.name}}</view>
 </picker-view-column>
 <picker-view-column class="selectItem">
 <view class="tooth" wx:for="{{area}}" wx:key="this">{{item.name}}</view>
 </picker-view-column>
</picker-view>

js部分

這部分代碼其實(shí)是因?yàn)楹蠖送瑢W(xué)太懶了,數(shù)據(jù)沒有整理就直接返回過來了。我人微言輕的,只好自己默默地整理了。

 // 把數(shù)據(jù)格式化成頁面現(xiàn)實(shí)的形式
 formatCityData: function () {
 var that = this,
 region = that.data.region,
 selectItems = [],
 province = [],
 city = [],
 area = [],
 area_index = that.data.area_index,
 city_index = that.data.city_index,
 province_index = that.data.province_index;
 // 第一遍格式化數(shù)據(jù),
 for (var i = 0; i < region.length; i++) {
 if (region[i].parent_id == 1) {
 var provinceItem = region[i];
 var selectItem1 = { label: provinceItem.zh_name, provinceId: provinceItem.id, children: [] };
 for (var j = 0; j < region.length; j++) {
  if (region[j].parent_id == provinceItem.id) {
  var cityItem = region[j];
  var selectItem2 = { label: cityItem.zh_name, cityId: cityItem.id, children: [] };
  selectItem1.children.push(selectItem2);
  for (var k = 0; k < region.length; k++) {
  if (region[k].parent_id == cityItem.id) {
  var areaItem = region[k];
  var selectItem3 = { label: areaItem.zh_name, areaId: areaItem.id, children: [] };
  selectItem2.children.push(selectItem3);
  }
  }
  }
 }
 selectItems.push(selectItem1);
 }
 }
 // 遍歷所有的數(shù)據(jù)。將省的名字放在對(duì)應(yīng)的數(shù)組中
 for (let i = 0; i < selectItems.length; i++) {
 province.push({
 name: selectItems[i].label,
 id: selectItems[i].provinceId
 });
 }
 if (selectItems[province_index].children && selectItems[province_index].children) {// 判斷選中的省級(jí)里面有沒有市
 if (selectItems[province_index].children[city_index]) {
 for (let i = 0; i < selectItems[province_index].children.length; i++) {
  city.push({
  name: selectItems[province_index].children[i].label,
  id: selectItems[province_index].children[i].cityId
  });
 }
 if (selectItems[province_index].children[city_index].children) {
  if (selectItems[province_index].children[city_index].children[area_index]) {
  for (let i = 0; i < selectItems[province_index].children[city_index].children.length; i++) {
  area.push({
  name: selectItems[province_index].children[city_index].children[i].label,
  id: selectItems[province_index].children[city_index].children[i].areaId
  });
  }
  } else {
  that.setData({
  area_index: 0
  });
  for (let i = 0; i < selectItems[province_index].children[city_index].childre.length; i++) {
  area.push({
  name: selectItems[province_index].children[city_index].children[i].label,
  id: selectItems[province_index].children[city_index].children[i].areaId
  });
  }
  }
 } else {
  area.push({
  name: province[province_index].children[city_index].label,
  id: province[province_index].children[city_index].areaId
  });
 }
 } else {
 that.setData({
  city_index: 0
 });
 for (let i = 0; i < selectItems[province_index].childre.length; i++) {
  city.push({
  name: selectItems[province_index].children[i].label,
  id: selectItems[province_index].children[i].cityId
  });
 }
 }
 } else {
 // 如果該省沒有市,那么就把省的名字作為市和區(qū)的名字
 city.push({
 name: province[province_index].label,
 id: province[province_index].cityId
 });
 area.push({
 name: province[province_index].label,
 id: province[province_index].areaId
 });
 }
 // 選擇成功后把對(duì)應(yīng)的數(shù)組賦值給相應(yīng)的變量
 that.setData({
 province: province,
 city: city,
 area: area
 });
 provincialCity = {
 province: {
 name: province[that.data.province_index].name,
 id: province[that.data.province_index].id,
 },
 city: {
 name: city[that.data.city_index].name,
 id: city[that.data.city_index].id
 },
 area: {
 name: area[that.data.area_index].name,
 id: area[that.data.area_index].id
 } 
 }
 },

后臺(tái)返回的格式如下:

// 選擇城市
 bindChange: function (e) {
 const val = e.detail.value;
 this.setData({
 province_index: val[0],
 city_index: val[1],
 area_index: val[2]
 });
 this.formatCityData();
 },

前面說的是新增收獲地址,后面是編輯

html部分

value就是用來回顯之前選擇的城市。

把整理好的省市區(qū)分別遍歷一下,把當(dāng)前的id與數(shù)據(jù)中的id作對(duì)比。把相對(duì)應(yīng)的數(shù)據(jù)的下標(biāo)給取出來。

this.data.province.map(function(val, key) {
 if (val.id === that.data.result.province.id) {
 provinceId = key;
 }
 return provinceId;
 })
 this.setData({
 province_index: provinceId
 });
 this.formatCityData();
 this.data.city.map(function(val, key) {
 if (val.id === that.data.result.city.id) {
 cityId = key;
 }
 return cityId;
 })
 this.setData({
 city_index: cityId
 });
 this.formatCityData();
 this.data.area.map(function (val, key) {
 if (val.id === that.data.result.area.id) {
 areaId = key;
 }
 return areaId;
 })
 var lists = [provinceId, cityId, areaId];
 this.setData({ cityShow: lists });

為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JavaScript數(shù)據(jù)結(jié)構(gòu)常見面試問題整理

    JavaScript數(shù)據(jù)結(jié)構(gòu)常見面試問題整理

    在JavaScript中,數(shù)據(jù)結(jié)構(gòu)是指相互之間存在一種或多種特定關(guān)系的數(shù)據(jù)元素的集合,是帶有結(jié)構(gòu)特性的數(shù)據(jù)元素的集合。常用的數(shù)據(jù)結(jié)構(gòu)有:數(shù)組、列表、棧、隊(duì)列、鏈表、字典、集合等等
    2022-08-08
  • 使用bootstrap莫名其妙出現(xiàn)橫向滾動(dòng)條的問題及解決

    使用bootstrap莫名其妙出現(xiàn)橫向滾動(dòng)條的問題及解決

    這篇文章主要介紹了使用bootstrap莫名其妙出現(xiàn)橫向滾動(dòng)條的問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • 小程序getLocation需要在app.json中聲明permission字段

    小程序getLocation需要在app.json中聲明permission字段

    這篇文章主要介紹了小程序getLocation需要在app.json中聲明permission字段,個(gè)別需要獲取用戶地理位置的在開發(fā)者工具調(diào)試時(shí)會(huì)出現(xiàn)getLocation需要在app.json中聲明permission字段 ,下面我們就一起來解決一下
    2019-04-04
  • MUI 實(shí)現(xiàn)側(cè)滑菜單及其主體部分上下滑動(dòng)的方法

    MUI 實(shí)現(xiàn)側(cè)滑菜單及其主體部分上下滑動(dòng)的方法

    下面小編就為大家分享一篇MUI 實(shí)現(xiàn)側(cè)滑菜單及其主體部分上下滑動(dòng)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • 輕松學(xué)習(xí)Javascript閉包函數(shù)

    輕松學(xué)習(xí)Javascript閉包函數(shù)

    這篇文章主要幫助大家輕松學(xué)習(xí)掌握J(rèn)avascript閉包函數(shù),從閉包的含義出發(fā),由淺入深學(xué)習(xí)Javascript閉包函數(shù),感興趣的小伙伴們可以參考一下
    2015-12-12
  • 詳細(xì)聊聊瀏覽器是如何看閉包的

    詳細(xì)聊聊瀏覽器是如何看閉包的

    閉包實(shí)質(zhì)上是函數(shù)作用域的副產(chǎn)物,下面這篇文章主要給大家介紹了關(guān)于瀏覽器是如何看閉包的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2021-11-11
  • JavaScript構(gòu)造函數(shù)舉例詳解

    JavaScript構(gòu)造函數(shù)舉例詳解

    Javascript構(gòu)造函數(shù)是非常強(qiáng)大的,它可能也是Javascript能被充分利用的特點(diǎn)之一,文中通過實(shí)例代碼介紹的非常詳細(xì),這篇文章主要給大家介紹了關(guān)于JavaScript構(gòu)造函數(shù)的相關(guān)資料,需要的朋友可以參考下
    2023-04-04
  • 關(guān)于二級(jí)域名下使用一級(jí)域名下的COOKIE的問題

    關(guān)于二級(jí)域名下使用一級(jí)域名下的COOKIE的問題

    我們通常在使用cookie的時(shí)候一般都只是局限在本站內(nèi)使用,也就是只在一個(gè)域名下使用
    2011-11-11
  • 純文字版返回頂端的js代碼

    純文字版返回頂端的js代碼

    這篇文章介紹了純文字版返回頂端的js代碼,有需要的朋友可以參考一下
    2013-08-08
  • js實(shí)現(xiàn)不重復(fù)導(dǎo)入的方法

    js實(shí)現(xiàn)不重復(fù)導(dǎo)入的方法

    這篇文章主要介紹了js實(shí)現(xiàn)不重復(fù)導(dǎo)入的方法,實(shí)例分析了JavaScript基于文件與字符串判斷操作實(shí)現(xiàn)JS文件不重復(fù)導(dǎo)入的相關(guān)技巧,需要的朋友可以參考下
    2016-03-03

最新評(píng)論

渝北区| 石家庄市| 漯河市| 栾川县| 泾川县| 乌拉特中旗| 新丰县| 沾化县| 贵德县| 界首市| 崇文区| 全椒县| 绥芬河市| 西贡区| 永寿县| 准格尔旗| 鄂伦春自治旗| 泸州市| 九台市| 剑川县| 怀宁县| 乐陵市| 高尔夫| 台东县| 汉中市| 诸暨市| 陇西县| 汉川市| 邮箱| 嫩江县| 丰顺县| 习水县| 韩城市| 四子王旗| 凤庆县| 扎囊县| 昭通市| 吴堡县| 延川县| 象州县| 东乌珠穆沁旗|