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

微信小程序?qū)崿F(xiàn)選擇內(nèi)容顯示對應(yīng)內(nèi)容

 更新時間:2022年07月19日 16:52:02   作者:山橘滿月  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)選擇內(nèi)容顯示對應(yīng)內(nèi)容,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

微信小程序中,經(jīng)??梢娺x擇地區(qū)或者商品分類或者其他的分類,選擇后顯示,選擇后刪除

先介紹一下主要功能:點擊 ‘地區(qū)’ ,下面選擇區(qū)域出現(xiàn),點擊 ‘選擇地區(qū)’ 中的按鈕,上面 ‘已選地區(qū)’ 顯示選擇的地區(qū),點擊 ‘x’ 已選的地區(qū)就取消,點擊 “完成” 整個選擇區(qū)域隱藏,只留下地區(qū)。

整體樣式用的彈性布局,就不細(xì)說了。

wxml:

<view class="container">
? <text bindtap="show" class="color">地區(qū)</text>
? <view class="choose" wx-if="{{a}}">
? ? <!-- 已選地區(qū) -->
? ? <view class="chosed">
? ? ? <view class="chosedtop">
? ? ? ? <text>已選地區(qū)</text>
? ? ? ? <text bindtap="finish">完成</text>
? ? ? </view>
? ? ? <view class="view">
? ? ? ? <view class="position" wx:for='{{area}}' wx:key='index'>
? ? ? ? ? <button class="buttond">{{item}}</button>
? ? ? ? ? <image src='' bindtap="shut" data-index="{{index}}" data-name="{{item}}"></image>
? ? ? ? ? //這是按鈕右上角的關(guān)閉圖片
? ? ? ? </view>
? ? ? </view>
? ? </view>
? ? <!-- 選擇地區(qū) -->
? ? <view class="area">
? ? ? <text>選擇地區(qū)</text>
? ? ? <view class="chos">
? ? ? ? <block wx:for='{{array}}' wx:key='index'>
? ? ? ? ? <button class="button {{tabindex == index?'active':''}}" data-index="{{index}}" data-name="{{item}}" bindtap="tabarea">{{item}}</button>
? ? ? ? </block>
? ? ? </view>
? ? </view>
? </view>
</view>

 js:

var chosedarea = [];
var area = [];
Page({?
? data: {
? ? a:false,
? ? tabindex:0,
? ? array: ["北京", '南京', '上海', '天津', '杭州', '云南', "北京", '南京', '上海', '天津', '杭州', '云南',"北京", '南京', '上海', '天津', '杭州', '云南'],
? },
? // 選地區(qū)
? ?tabarea:function(e){
? ? this.setData({
? ? ? tabindex:e.currentTarget.dataset.index
? ? });
? ? ?var id = e.currentTarget.dataset.index;
? ? ?var name = e.currentTarget.dataset.name;
? ? ?chosedarea.push(name);
? ? ? ?this.setData({
? ? ? ? ?"area": chosedarea
? ? ? ?})
? },
? // 取消已選地區(qū)
? shut:function(e){
? ? this.setData({
? ? ? index: e.currentTarget.dataset.index,
? ? ? name : e.currentTarget.dataset.name
? ? });
? ? var yid = e.currentTarget.dataset.index;
? ? var yname = e.currentTarget.dataset.name;
? ? chosedarea.splice(yid,1)
? ? this.setData({
? ? ? "area": chosedarea
? ? })
? },
? // 點擊完成隱藏
? finish:function(){
? ? var that = this;
? ? if (that.data.a == true) {
? ? ? that.setData({
? ? ? ? a: false ??
? ? ? })
? ? }
? },
? // 點擊地區(qū)顯示
? show:function(){
? ? var that = this;
? ? if (that.data.a == false) {
? ? ? that.setData({
? ? ? ? a: true ? ?
? ? ? })
? ? }
? },
? })

css

.container{
? width: 100%;
? height: 300rpx;
}
.choose{
? width: 100%;
}
.buttond{
? width: 88%;
? padding: 0;
? height: 68rpx;
? line-height: 68rpx;
? font-size: 32rpx;
? margin-bottom: 10rpx;
}
.area{
? display: flex;
? flex-direction: column;
? margin: 0 20rpx;
}
.chos{
? display: flex;
? flex-wrap: wrap;
? margin-top: 15rpx;
}
.button{
? width: 22%;
? padding: 0;
? height: 68rpx;
? line-height: 68rpx;
? font-size: 32rpx;
? margin: 0 10rpx;
? margin-bottom: 10rpx;
}
.view{
? display: flex;
? flex-wrap: wrap;
? height: auto;
? margin: 0 20rpx;
}
.position{
? width: 24%;
}
.chosedtop{
? display: flex;
? justify-content: space-between;
? margin: 0 30rpx 15rpx
}

如果是選完 上面添加了對應(yīng)的 下面可選擇的與之對應(yīng)的要隱藏掉 就這樣: 

 js中

// 選地區(qū)
? tabarea: function (e) {
? ? let that = this;
? ? that.setData({
? ? ? tabindex: e.currentTarget.dataset.index
? ? });
? ? var id = e.currentTarget.dataset.index;
? ? var name = e.currentTarget.dataset.name;
? ? chosedarea.push(name);
? ? that.data.array.splice(id, 1);
? ? that.setData({
? ? ? "area": chosedarea,
? ? ? "array": that.data.array
? ? })
? },

在上面點擊刪除的話 下面可選擇的區(qū)域要對應(yīng)的添加上:

wxml:

<view class="container">
? <text bindtap="show" class="color">地區(qū)</text>
? <view class="choose" wx-if="{{a}}">
? ? <!-- 已選地區(qū) -->
? ? <view class="chosed">
? ? ? <view class="chosedtop">
? ? ? ? <text>已選地區(qū)</text>
? ? ? ? <text bindtap="finish">完成</text>
? ? ? </view>
? ? ? <view class="view">
? ? ? ? <view class="position" wx:for='{{area}}' wx:key='index'>
? ? ? ? ? <button class="buttond" data-index="{{index}}" data-name="{{item}}" bindtap="addName">{{item}}</button>
? ? ? ? ? <!-- <image src='' bindtap="shut" data-index="{{index}}" data-name="{{item}}"></image> -->
? ? ? ? ? <!-- //這是按鈕右上角的關(guān)閉圖片 -->
? ? ? ? </view>
? ? ? </view>
? ? </view>
? ? <!-- 選擇地區(qū) -->
? ? <view class="area">
? ? ? <text>選擇地區(qū)</text>
? ? ? <view class="chos">
? ? ? ? <block wx:for='{{array}}' wx:key='index'>
? ? ? ? ? <button class="button {{tabindex == index?'active':''}}" data-index="{{index}}" data-name="{{item}}" bindtap="tabarea">{{item}}</button>
? ? ? ? </block>
? ? ? </view>
? ? </view>
? </view>
</view>

js

var chosedarea = [];
var area = [];
Page({
? data: {
? ? a: false,
? ? tabindex: 0,
? ? array: ["北京", '南京', '上海', '天津', '杭州', '云南', "新疆", '黑龍江', '東北', '威海', '寧夏', '廣西', "西安", '山東', '青島', '濟(jì)南', '煙臺', '蓬萊'],
? },
? // 選地區(qū)
? tabarea: function (e) {
? ? let that = this;
? ? that.setData({
? ? ? tabindex: e.currentTarget.dataset.index
? ? });
? ? var id = e.currentTarget.dataset.index;
? ? var name = e.currentTarget.dataset.name;
? ? chosedarea.push(name);
? ? that.data.array.splice(id, 1);
? ? that.setData({
? ? ? "area": chosedarea,
? ? ? "array": that.data.array
? ? })
? },
? // 添加回
? addName:function(e){
? ? let that = this;
? ? console.log(e)
? ? that.setData({
? ? ? index: e.currentTarget.dataset.index,
? ? })
? ? var aname = e.currentTarget.dataset.name;
? ? chosedarea.splice(that.data.index,1);
? ? that.data.array.push(aname);
? ? that.setData({
? ? ? "area": chosedarea,
? ? ? "array": that.data.array
? ? })
? },
? // 取消已選地區(qū)
? shut: function (e) {
? ? this.setData({
? ? ? index: e.currentTarget.dataset.index,
? ? ? name: e.currentTarget.dataset.name
? ? });
? ? var yid = e.currentTarget.dataset.index;
? ? var yname = e.currentTarget.dataset.name;
? ? chosedarea.splice(yid, 1)
? ? this.setData({
? ? ? "area": chosedarea
? ? })
? },
? // 點擊完成隱藏
? finish: function () {
? ? var that = this;
? ? if (that.data.a == true) {
? ? ? that.setData({
? ? ? ? a: false
? ? ? })
? ? }
? },
? // 點擊地區(qū)顯示
? show: function () {
? ? var that = this;
? ? if (that.data.a == false) {
? ? ? that.setData({
? ? ? ? a: true
? ? ? })
? ? }
? },
})

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

相關(guān)文章

最新評論

滕州市| 喀什市| 三原县| 垣曲县| 日照市| 肃宁县| 江西省| 沽源县| 红河县| 建昌县| 大渡口区| 平武县| 工布江达县| 黄陵县| 武平县| 务川| 敦煌市| 哈密市| 保康县| 南投县| 宁强县| 玉溪市| 威海市| 卫辉市| 邵阳市| 临沭县| 日喀则市| 嫩江县| 从化市| 商都县| 海兴县| 和田市| 读书| 黄浦区| 荥阳市| 铜川市| 博罗县| 马山县| 称多县| 阳春市| 民权县|