当前位置:网站首页>Wechat applet is bound to a dynamic array to implement a custom radio box (after clicking the button, disable the button and enable other buttons)
Wechat applet is bound to a dynamic array to implement a custom radio box (after clicking the button, disable the button and enable other buttons)
2022-06-26 04:01:00 【Box bridge】
Notes :
Recently, I am learning wechat applet and participating in my own embedded control project , The front end doesn't know much , Encountered many problems , Right here , Take notes piecemeal .
Here is how to use the wechat applet WXML Tag binding JS The array in can control the batch of keys in the loop .
1、 Implement dynamic binding
First, let's take a look at how a single key is dynamically bound , adopt { { Variable name }} The form will be JS The variables in are passed to the corresponding attributes
<view>
<button disabled="{
{disabled}}" bindtap="Button_1"> Button 1</button>
</view>
Corresponding JS Code , Here and standard JavaScript The difference is that you can't use
document.getElementById("p1").innerHTML=" New text !"; To get the corresponding HTML Node information in , And get permission to modify , And you want to use setData() function , The reference codes are as follows .
Page({
data: {
disabled:false,
},
Button_1(){
this.setData({
disabled:false,
})
},
})2、 Implement array dynamic binding
In the form of an array JS In the definition of disable:[{}], stay WXML Reference... In tag attribute , Because it is very small here , The events that took a long time to click with the three buttons are Button_1 Here is just a demonstration of a button pressed , Other buttons disable Property changed to false, The other buttons are enabled , Similar to radio buttons .
Can be applied to " Start connecting "—>" disconnect "—>“ End of service " And other procedural button operations .
<view>
<button disabled="{
{disabled[1].value}}" bindtap="Button_1"> Button 1</button>
<button disabled="{
{disabled[2].value}}" bindtap="Button_2"> Button 2</button>
<button disabled="{
{disabled[3].value}}" bindtap="Button_3"> Button 3</button>
</view>
In the wechat app JS There are some standards in the JS Different grammar , The wechat applet development team may be considering some factors , Some of the writing has been modified , But if you master it, you can still use it very well .
Page({
data: {
disabled:[
{value:false,},{value:true},{value:true},//***** The point *****//
]
},
Button_1(){
for(let i = 2; i <= 3;i++)
let temp = 'diasbled['+i+'].value'//***** The point *****//
this.setData({
temp:false
}),
})stay JS There are two points to note in :let temp = 'diasbled['+i+'].value', I have used string connection disable[i].value and WXML As called in , But because of setData This form is not allowed in , So we have to define a temporary variable to assume the name reference function , Then use the same temp:false To operate .
Array of disable stay data:{} Pay attention to the syntax when defining , I'm through i Do it directly index Indexed .
In addition, there is a very deep pit , That is, if the keyword has no other color on the table , The following figure id3 hinder value:ture It's a mistake , He doesn't think so ture The definition of .

——————
I hope the notes are helpful to you !
边栏推荐
- 【Flink】Flink源码分析——批处理模式JobGraph的创建
- 在出海获客这件事上,数字广告投放之外,广告主还能怎么玩儿?
- Introduction Guide to the flutterplugin plug-in in the actual combat of flutter
- Open camera anomaly analysis (I)
- Prism framework
- 用eclipse连mysql数据库出错然后出现图中的话是咋回事呀
- 链路监控 pinpoint
- MapReduce执行原理记录
- But the Internet began to have a new evolution and began to appear in a new state
- matplotlib折线图,文字显示,win10
猜你喜欢

捕获数据包(Wireshark)

Threejs专用天空盒素材,五种天空盒素材免费下载
![[collection of good books] from technology to products](/img/b1/a119d61ff20d19d1e42e5c243de42c.png)
[collection of good books] from technology to products
![[QT] resource file import](/img/0f/6eff57a09edda284b833947dab16af.png)
[QT] resource file import

EF core Basics

YOLOv5改进:更换骨干网(Backbone)

Custom parameter QR code picture combined with background picture to generate new picture node environment

Spark - understand parquet

ABP framework Practice Series (II) - Introduction to domain layer
![[Flink] Flink batch mode map side data aggregation normalizedkeysorter](/img/c7/611c7207730555b510505d4a8efe3d.png)
[Flink] Flink batch mode map side data aggregation normalizedkeysorter
随机推荐
判断两个集合的相同值 ||不同值
EF core Basics
Spark - 一文搞懂 parquet
线程同步之互斥量(互斥锁)
763. 划分字母区间
xml 解析bean工具类
Introduction Guide to the flutterplugin plug-in in the actual combat of flutter
Is the waiting insurance record a waiting insurance evaluation? What is the relationship between the two?
English version of ternary loss
How to use EEPROM in 51 Single Chip Microcomputer?
【Flink】Flink 批处理模式Map端数据聚合 NormalizedKeySorter
Machine learning notes - trend components of time series
Question brushing record day01
Intelligent manufacturing learning videos and books
Yolov5 improvements: replace the backbone
Verrouillage de lecture et d'écriture pour la synchronisation des fils
Alibaba cloud function computing service one click to build Z-blog personal blog
[QT] resource file import
Introduction of mybatis invalid
Prism framework