当前位置:网站首页>Custom attribute acquisition of view in applet
Custom attribute acquisition of view in applet
2022-06-13 06:34:00 【Sindyue】
When you click on a component during applet development, you need to get some properties of the currently clicked image , Such as the current location or picture link , At this point, you can get the through the custom attribute .
1. Definition
Identification of custom attributes data-attrName , Behind them “attrName” Name it casually , Prefix “data-” Is a must .
2. Use
stay wxml The following code is added to the file :
<image class="image-style" data-src='{
{imgSrc}}' src="{
{imgSrc}}" bindtap="previewImage"></image>
Then the preview interface can be shown as follows :
// The preview image
previewImage: function(e) {
var current = e.target.dataset.src;
wx.previewImage({
current: current, // The http link
urls: this.data.imgList // Pictures that need to be previewed http Link list
})
},
3. e.target And e.currentTarget
e.target Take the properties of the clicked object ;
If it is data- Put it on the outer layer , You can't get the attribute value by clicking on the element inside ;
While using e.currentTarget Is to take bintap/catchtap Property of the object in which the ~, Click on the element inside to get the attribute value .
<view class='a-child' data-tid='{
{child.ID}}' bindtap='selectChild'>
<image class='avatar' src='../../images/localImages/default_user.png'></image>
<view class='child-mid'>
<view class='mid-top child-name'>{
{child.STUDENTNAME}}</view>
</view>
</view>
Example Need to take tid To be as follows :
selectChild: function(e) {
// obtain ID
var tid = e.currentTarget.dataset.tid
console.log('tid: ' + tid)
},
边栏推荐
- Construction and verification of Alibaba cloud server webrtc system
- Ijkplayer code walk through H264 unpacker application details
- JVM Foundation
- The web server failed to start Port 7001 was already in use
- Echart line chart: multiple line charts show only one line at a time
- Wechat applet: click the event to obtain the current device information (basic)
- [SketchUp 2021] CAD file import and modeling in the sketch master (establish elevation model in the sketch master by using CAD drawings), and the sketch master exports 2D, 3D and elevation effects of
- 端午安康,使用祝福话语生成词云吧
- Echart rectangular tree diagram: simple implementation of rectangular tree diagram
- Download and installation of universal player potplayer, live stream m3u8 import
猜你喜欢
MFS explanation (V) -- MFS metadata log server installation and configuration
Detailed explanation of PHP distributed transaction principle
[virtual machine] VMware virtual machine occupies too much space. Solution
华为开发者认证与DevEco Studio编译器下载
‘ipconfig‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
[FAQs for novices on the road] understand program design step by step
Recommend a capacity expansion tool to completely solve the problem of insufficient disk space in Disk C and other disks
【新手上路常见问答】一步一步理解程序设计
二分查找
MFS explanation (VI) -- MFS chunk server installation and configuration
随机推荐
Kotlin collaboration -- context and exception handling
Analysis of synchronized
App performance test: (II) CPU
RFID process management solution for electroplating fixture
Detailed explanation of PHP distributed transaction principle
Detailed explanation of the player startup process of ijkplayer code walkthrough 2
华为开发者认证与DevEco Studio编译器下载
[var const let differences]
Error in downloading opencv from pip
Echart histogram: stack histogram value formatted display
Binary search
The web server failed to start Port 7001 was already in use
JetPack - - - LifeCycle、ViewModel、LiveData
[2022 college entrance examination season] what I want to say as a passer-by
Local file search tool everything
App performance test: (III) traffic monitoring
Kotlin data flow - flow
[SketchUp 2021] CAD file import and modeling in the sketch master (establish elevation model in the sketch master by using CAD drawings), and the sketch master exports 2D, 3D and elevation effects of
Ijkplayer code walk through H264 unpacker application details
‘ipconfig‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。