微信小程序e.currentTarget.dataset获取不到数据的问题

项目场景:

最近写一个微信小程序,使用抽屉组件,需要获取点击事件数据


问题描述:

bindtap=“showModal1” data-target=“Modal” data-personInfo="{{drawerPeople[index]}}"使用e.currentTarget.dataset.personInfo怎么都获取不到数据,找不到原因

<!-- 抽屉 人员列表-->
<view class="cu-modal drawer-modal justify-start {{modalName=='DrawerModalL'?'show':''}}" bindtap="hideModal">
  <view class="cu-dialog basis-lg" catchtap style="top:{{CustomBar}}px;height:calc(100vh - {{CustomBar}}px)">
    <scroll-view class="scrollList" scroll-y style="height:calc(100vh - {{CustomBar}}px)">
      <view class="cu-list menu text-left">
        <view class="cu-item arrow" wx:for="{{drawerPeople}}" wx:key="index" bindtap="showModal1" data-target="Modal" data-personInfo="{{drawerPeople[index]}}">
          <view class="content">
            <text class="cuIcon-github text-grey"></text>
            <text class="text-grey">{{item.personName}}</text>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</view>
<!-- 抽屉 人员列表-->

原因分析:

通过console.log(e)发现e.currentTarget.dataset.personInfo中personInfo变成了personinfo,大写变小写了,变量名改变导致无法获取变量数据,由此猜测这里变量名只能采用全小写命名,“date-name”中name字段名称不能用大写,从wxml传给js的时候,大写变量名自动变全小写,导致获取不到变量数据。


<hr style=" border:solid; width:100px; height:1px;" color=#000000 size=1">
{type: "tap", timeStamp: 35913, target: {}, currentTarget: {}, mark: {},}
changedTouches: [{}]
currentTarget:
dataset:
personinfo: {_id: "",}
target: "Modal"
__proto__: Object
id: ""
offsetLeft: 0
offsetTop: 210

解决方案:

将“date-name”中name字段名称改用全小写,解决问题。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值