微信小程序?qū)崿F(xiàn)select二級下拉
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)select二級下拉的具體代碼,供大家參考,具體內(nèi)容如下
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({
? /**
? ?* 頁面的初始數(shù)據(jù)
? ?*/
? data: {
? ? liebiao:[],
? ? price:[],
? ? index:0,
? ? area:[],
? ? areaId:'',
? ? dian:[]
? },
??
? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁面加載
? ?*/
? onLoad: function (options) {
? ?var that = this;
? ?that.area();
? ?
? },
// 獲取區(qū)域
area(){
? var that = this;
? ? wx.request({
? ? ? url: 'xxxxxx',
? ? ? header: {
? ? ? ? 'content-type': 'application/json' // 默認(rèn)值
? ? ? },
? ? ? 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();
? ? ? }
? ? ??
? ? })
? ??
},
// 點(diǎn)擊改變區(qū)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
? }
? })
},
? // 點(diǎn)擊下拉顯示框
? dianTap() {
? ? this.setData({
? ? ? dianShow: !this.data.dianShow
? ? });
? },
? // 點(diǎn)擊下拉列表
? optionTap(e) {
? ? let Index = e.currentTarget.dataset.index;//獲取點(diǎn)擊的下拉列表的下標(biāo)
? ? 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;
}界面比較原始,建議自行美化
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript實(shí)現(xiàn)指定數(shù)量的并發(fā)限制的示例代碼
這篇文章主要介紹了JavaScript實(shí)現(xiàn)指定數(shù)量的并發(fā)限制的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
javascript下利用數(shù)組緩存正則表達(dá)式的實(shí)現(xiàn)方法
利用組存大法要提高我們程序的性能,讓我們的正則表達(dá)式的創(chuàng)建于執(zhí)行更有效率。2009-12-12
js實(shí)現(xiàn)的簡潔網(wǎng)頁滑動tab菜單效果代碼
這篇文章主要介紹了js實(shí)現(xiàn)的簡潔網(wǎng)頁滑動tab菜單效果代碼,可實(shí)現(xiàn)簡單的鼠標(biāo)滑過tab標(biāo)簽切換的功能,非常簡單實(shí)用,需要的朋友可以參考下2015-08-08
JavaScript設(shè)計(jì)模式之構(gòu)造器模式(生成器模式)定義與用法實(shí)例分析
這篇文章主要介紹了JavaScript設(shè)計(jì)模式之構(gòu)造器模式(生成器模式)定義與用法,結(jié)合實(shí)例形式分析了javascript構(gòu)造器模式的概念、原理、與工廠模式的區(qū)別以及相關(guān)使用方法,需要的朋友可以參考下2018-07-07
javascript高級程序設(shè)計(jì)第二版第十二章事件要點(diǎn)總結(jié)(常用的跨瀏覽器檢測方法)
javascript高級程序設(shè)計(jì)第二版第十二章事件要點(diǎn)總結(jié)(常用的跨瀏覽器檢測方法),需要的朋友可以參考下2012-08-08
javascript之典型高階函數(shù)應(yīng)用介紹
這幾個(gè)方法均為javascript 1.6 數(shù)組新增的方法。是很典型的functional 函數(shù),當(dāng)然也非常實(shí)用。下面是functional的定義并不來自javascript2013-01-01

