溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

微信小程序如何實現select二級下拉

發布時間:2022-07-19 17:26:32 來源:億速云 閱讀:275 作者:iii 欄目:開發技術

本篇內容主要講解“微信小程序如何實現select二級下拉”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“微信小程序如何實現select二級下拉”吧!

xiala.wxml

<!-- 列表選擇 -->
<view class="list" hover-class="none" hover-stop-propagation="false">
    <text class="listText dd">3.請選擇門店</text>
    <view class="box" hover-class="none" hover-stop-propagation="false">
        <view class='select_box'>
            <view class='select' catchtap='dianTap'>
                <input type="number" class='select_text' disabled="true" adjust-position="flase"
                    value="{{dian[index]}}" name="lie" />
                <image class='select_img {{dianShow&&"select_img_rotate"}}' src='/pages/image/b2.png'
                    background-size="contain"></image>
            </view>
            <view class="option_bbox" hover-class="none" hover-stop-propagation="false">
               <view class='option_box' style='height:{{dianShow?(area.length>5?325:dian.length*70):0}}rpx;'>
                <text class='option' wx:for='{{area}}' wx:key='this' data-index='{{index}}' data-aid='{{item.id}}'  catchtap='areaId'>{{item.name}}</text>
            </view>
            <view class='option_box' style='height:{{dianShow?(dian.length>5?325:dian.length*70):0}}rpx;'>
                <text class='option' wx:for='{{dian}}' wx:key='this' data-index='{{dian}}' catchtap='optionTap'>{{item}}</text>
            </view> 
            </view>
            
        </view>
    </view>

</view>

js頁面

// pages/xiala/xiala.js
Page({

  /**
   * 頁面的初始數據
   */
  data: {
    liebiao:[],
    price:[],
    index:0,
    area:[],
    areaId:'',
    dian:[]
  },
  

  /**
   * 生命周期函數--監聽頁面加載
   */
  onLoad: function (options) {
   var that = this;
   that.area();
   
  },
// 獲取區域
area(){
  var that = this;
    wx.request({
      url: 'xxxxxx',
      header: {
        'content-type': 'application/json' // 默認值
      },
      success(res) {
        console.log(res.data)
        let area = res.data.data;
        let obMut = [];
        let areaId;
        for(var i=0; i<area.length;i++){
          areaId = area[0].id;
          obMut.push({id:area[i].id,name:area[i].name});
          }
          
          that.setData({
            areaId:areaId,
            area:obMut
           })
          //  console.log(that.data.areaId)
          that.dian();
      }
      
    })
    
},
// 點擊改變區id
areaId(e){
  var that = this;
  that.setData({
    areaId: e.currentTarget.dataset.aid,
  })
  that.dian();
},
// 獲取店
dian:function(){
  let that = this;
  let idx =that.data.areaId;
  let area = that.data.area;
  console.log(area)
  area.forEach((item, index) => {
    if (idx === item.id) {
      item.status = true
      wx.request({
        url: 'xxxxxxx',
        dataType: 'json',
        method: 'POST',
        header: {
         'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: {
          aid: item.id
        },
        success(res) {
          // console.log(res)
          let fmutA = that.data.fmutA;
          if (res.data.status === 1) {
          console.log(res.data.shop)
          
          let dian = res.data.shop;
          let fDian = [];
          
          for(var i=0; i<dian.length;i++){
            fDian[i] = dian[i].name;
            }
          console.log(fDian)
          that.setData({
            dian: fDian,
           })
        }
          
  
        }
      })
  }else{
    item.status = false
  }
  })
},
  // 點擊下拉顯示框
  dianTap() {
    this.setData({
      dianShow: !this.data.dianShow
    });
  },
  // 點擊下拉列表
  optionTap(e) {
    let Index = e.currentTarget.dataset.index;//獲取點擊的下拉列表的下標
    this.setData({
      index: Index,
      dianShow: !this.data.dianShow
    });
  }
})

wxss頁面

/* 列表 */
/* pages/map/map.wxss */
.select_box{
  width: 63%;
  height:70%;
  border-radius: 14rpx;
  position: relative;
}
.select_box .select{
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  border-radius: 8rpx;
  display: flex;
  align-items: center;
}
.select_box .select .select_text{
  color: #777777;
  line-height: 28rpx;
  flex: 1;
}
.select_box .select .select_img{
  width: 20rpx;
  height: 20rpx;
  display: block;
  transition:transform 0.3s;
  position: absolute;
  right: 25rpx;
}
.select_box .select .select_img_rotate{
  transform:rotate(180deg); 
}
.select_box .option_box{
position: absolute;
top: calc(100% - 1px);
width: 100%;
box-sizing: border-box;
height: 0;
overflow-y: auto;
background: #fff;
transition: height 0.3s;
border: 1px solid #efefef;
border-right: 1px solid #efefef;
background: #fcfcfc;
}
.select_box .option_box .option{
  display: block;
  line-height: 38rpx; 
  font-size: 9pt;
  border-top: 1px solid #efefef;
  border-bottom: 1px solid #efefef;
  padding: 10rpx;
}
.option_bbox{
    display: flex;
    justify-content: row;
}
.select_box .option_box {
    position: relative;
}

到此,相信大家對“微信小程序如何實現select二級下拉”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女