当前位置:网站首页>Wechat applet -picker component is repackaged and the disabled attribute is added -- below
Wechat applet -picker component is repackaged and the disabled attribute is added -- below
2022-06-26 13:36:00 【woowen!】
Click here Wechat applet -picker Component reseal increase disabled attribute -- Above,
In the last article, I mentioned the repackaged picker The effect of the component is as follows :
When picker When one of the items is not selectable , It will be as shown in the figure below , The color is grey , And the user cannot click to select .


The following code can be directly copied and pasted ~
The native form component of wechat is used here picker-view and picker-view-column, You can check how to use it by yourself
custom-picker The component code is expanded as follows :
//custome-picker.wxml
<view>
<slot></slot>
<view class="picker-container" style="{
{showflag?'display:blcok':'display:none'}}">
<view class="shadow" catchtap="eventCancel" catchtouchmove="{
{true}}"></view>
<view class="wrap wrap-position">
<view class="wrap-top">
<text class="left-btn" catchtap="eventCancel"> Cancel </text>
<text class="right-btn" catchtap="eventSure"> determine </text>
</view>
<!-- Scroll content -->
<picker-view
indicator-style="height: 50px;"
style="width: 100%; height: 200px;"
value="{
{value}}"
bindchange="bindChange">
<picker-view-column>
<view
wx:for="{
{range}}"
wx:key="index"
style="{
{item.disabled ? 'color:#cdcdcd;line-height: 50px; text-align: center;' :'line-height: 50px; text-align: center;'}}"
>{
{item[rangeKey]}}</view>
</picker-view-column>
</picker-view>
</view>
</view>
</view>
// custom-picker.js
Component({
properties:{
range:{
type: Array,
},
rangeKey: { // Cyclic display of bytes
type: String,
default(){
return ''
}
},
value: String
},
// internal data
data: {
showflag: false,
setValue: [0],// The first item is selected by default
},
onLoad(){},
methods: {
// Click cancel event
eventCancel(){
this.setData({
showflag: !this.data.showflag
})
},
// Click OK event
eventSure(){
// If the option is grayed out , This option is prohibited
const selectObj = this.data.range[this.data.setValue[0]]
if(selectObj.hasOwnProperty('disabled') && selectObj.disabled){
return
}
this.setData({
showflag: !this.data.showflag
})
let item = this.data.setValue[0] || "0" // Selected information - If it doesn't trigger bindChange, The first message is selected by default
this.triggerEvent('customEvent',item)
},
// Show picker
showPicker: function(e){
this.setData({
showflag: !this.data.showflag
})
},
// Scroll Events
bindChange(e){
this.setData({
setValue: e.detail.value,
})
}
}
})//custome-picker.wxss
.shadow{
background: #000000;
opacity: 0.6;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 101;
width: 100%;
height: 100%;
overflow: hidden;
}
.wrap{
width: 100%;
height: 600rpx;
background-color: #ffffff;
}
.wrap-position{
position: fixed;
z-index: 102;
bottom: 0;
left: 0;
right: 0;
}
.wrap-top{
height: 100rpx;
line-height: 100rpx;
border-bottom: 1rpx solid #e3e4e5;
}
.wrap .left-btn{
float: left;
padding-left: 30rpx;
color: #b1b2b3;
font-size: 36rpx;
}
.wrap .right-btn{
color: #07c160;
float: right;
padding-right: 30rpx;
font-size: 36rpx;
}
//custom-picker.json
{
"component": true
}The problems encountered here :
1. The applet mask layer scrolls to prevent penetration problems
Adds... To the current mask layer catchtouchmove="{ {true}}" that will do , There is a phenomenon that it has no effect on developer tools , Can still slide , But mobile phone test ios/andriod It can realize the effect of prohibiting scrolling !
2. Applet setData Dynamic variable problem
3. The above relates to The applet prevents events from bubbling The problem of
边栏推荐
- ES基於Snapshot(快照)的數據備份和還原
- Bifu divides EtherCAT module into multiple synchronization units for operation -- use of sync units
- 遍历指定目录获取当前目录下指定后缀(如txt和ini)的文件名
- Sed editor
- HW蓝队溯源流程详细整理
- 三维向量的夹角
- Create your own cross domain proxy server
- Guruiwat rushed to the Hong Kong stock exchange for listing: set "multiple firsts" and obtained an investment of 900million yuan from IDG capital
- Beifu twincat3 can read and write CSV and txt files
- 古瑞瓦特冲刺港交所上市:创下“多个第一”,获IDG资本9亿元投资
猜你喜欢

Arcpy——InsertLayer()函數的使用:摻入圖層到地圖文檔裏

Electron official docs series: Get Started

MySQL讲解(二)

Beifu PLC realizes data power-off maintenance based on cx5130

Create your own cross domain proxy server

Mongodb series window environment deployment configuration

Composite mode
![[how to connect the network] Chapter 2 (middle): sending a network packet](/img/5f/602c59d3a7ee1154c7410fb2fcfc41.png)
[how to connect the network] Chapter 2 (middle): sending a network packet

ES6:Map

Ring queue PHP
随机推荐
Ring queue PHP
Beifu PLC realizes zero point power-off hold of absolute value encoder -- use of bias
12 SQL optimization schemes summarized by old drivers (very practical)
输入文本自动生成图像,太好玩了!
偶言佳句,孤芳自赏
Traverse the specified directory to obtain the file name with the specified suffix (such as txt and INI) under the current directory
Beifu cx5130 card replacement and transfer of existing authorization files
Arcpy -- use of insertlayer() function: adding layers to map documents
7-2 a Fu the thief
Electron official docs series: Best Practices
Taishan Office Technology Lecture: four cases of using bold font
Electron official docs series: Contributing
Solutions to insufficient display permissions of find and Du -sh
MySQL explanation (II)
Zoomeeper sets ACL permission control (only specific IP access is allowed to enhance security)
【Spark】. Explanation of several icons of scala file in idea
7-1 range of numbers
7-2 picking peanuts
code force Party Lemonade
Electron official docs series: Examples