微信小程序實現列表條件篩選
本文實例為大傢分享瞭微信小程序實現列表條件篩選的具體代碼,供大傢參考,具體內容如下
最近一個旅遊項目,關於篩選框的代碼
wxml文件
<view class='chooseList'> <view class="nav"> <view class="nav-son {{shownavindex == 1? 'active' : ''}}" bindtap="listqy" data-nav="1"> <view class="content">酒店類型</view> <view class="icon"></view> </view> <view class="nav-son borders {{shownavindex == 2? 'active' : ''}}" bindtap="list" data-nav="2"> <view class="content">價格</view> <view class="icon"></view> </view> <!-- <view class="nav-son {{shownavindex == 3? 'active' : ''}}" bindtap="listpx" data-nav="3"> <view class="content">排序</view> <view class="icon"></view> </view> --> </view> <view class="quyu {{qyopen ? 'slidown' : 'slidup'}} {{qyshow ? 'disappear':''}}"> <view class="qy quyu-left"> <view class="{{select1 == index ? 'current' : ''}}" wx:for="{{cityleft}}" wx:key='{{item}}' bindtap="selectleft" data-city='{{index}}'> {{index}} </view> </view> <view class="qy quyu-center"> <view class="{{select2 == index ? 'current2' : ''}}" wx:for="{{citycenter}}" bindtap="selectcenter" data-value='{{item}}' data-city='{{index}}'> {{index}} <image src='../../images/istrue.png' style="{{select2 == index?'display:block':'display:none'}}"></image> </view> <!-- 如果選擇是早餐,展示篩選按鈕 --> <view style="border-style: none;" wx:if='{{isshowradio}}'> <radio-group class="radio-group" bindchange="radioChange"> <label class="radio" wx:for="{{breakfastlist}}"> <radio value="{{item.value}}" checked="{{item.checked}}" /> {{item.value}} </label> </radio-group> </view> </view> <view class='form-btn'> <button class='btn-reset' bindtap='quyuEmpty'>重置</button> <button class='btn-submit' bindtap='submitFilter'>確定</button> </view> </view>
js文件:
點擊酒店類型,展示篩選酒店的條件
listqy: function (e) { console.log('觸發時機---點擊酒店類型的時候') if (this.data.qyopen) { console.log(this.data.qyopen) this.setData({ qyopen: false, nzopen: false, nzshow: true, qyshow: false, isfull: false, shownavindex: 0 }) } else { this.setData({ qyopen: true, nzopen: false, nzshow: true, qyshow: false, isfull: true, shownavindex: e.currentTarget.dataset.nav }) } },
點擊一級菜單,展示對應的二級菜單
selectleft: function (e) { console.log('用戶選中左邊菜單欄的索引值是:' + e.target.dataset.city); if (e.target.dataset.city === '床型、早餐') { console.log('哈哈') this.setData({ isshowradio: true // 如果是早餐和床型的話,就讓選擇早餐的按鈕顯示 }) } else { this.setData({ isshowradio: false }) } this.setData({ citycenter: this.data.cityleft[e.currentTarget.dataset.city], select1: e.target.dataset.city, select2: '' }); },
點擊二級菜單
selectcenter: function (e) { console.log(e.target.dataset.value) console.log('用戶選中右邊邊菜單欄的索引值是:' + e.target.dataset.value, this.data.select1); let _this = this if (_this.data.select1 === '酒店類型') { _this.data.type = e.target.dataset.city console.log(_this.data.type) } if (_this.data.select1 === '設施') { _this.data.facility = e.target.dataset.city console.log(_this.data.facility) } if (_this.data.select1 === '地理位置') { _this.data.maxdistance = e.target.dataset.value console.log(_this.data.maxdistance) } if (_this.data.select1 === '床型、早餐') { _this.data.cbedtype = e.target.dataset.city console.log(_this.data.cbedtype) } this.setData({ select2: e.target.dataset.city }); },
以上就是本文的全部內容,希望對大傢的學習有所幫助,也希望大傢多多支持WalkonNet。