微信小程序bindtap方法传参

通过 "data-参数名" 的方式绑定

WXML

<view class='faq'>
  <view class='own-data_none' style="display: {{ askAnswers.length == 0 ? 'block' : 'none' }}">{{no_faq_record_msg}}</view>
  <view wx:if="{{ askAnswers.length > 0 }}">
    <view wx:for="{{askAnswers}}" wx:key="*this" bindtap='toggle' data-index="{{index}}" data-item="{{item}}">
      <view class='dt'>{{item.ask}}</view>
      <view class='dd' style="display: {{ item.showAnswer ? 'block' : 'none' }}">{{item.answer}}</view>
    </view>
  </view>
</view>

JS

toggle(e) {
  var index = e.currentTarget.dataset.index
  var item = e.currentTarget.dataset.item
  //
}
上一篇 微信小程序自定义radio和checkbox样式
下一篇 微信小程序中this指向作用域问题this.setData is not a function报错
目录
文章列表
1 Android退出应用程序探讨
Android退出应用程序探讨
2
Flutter中自动执行onTap事件解决
Flutter中自动执行onTap事件解决
3
Spring Cloud Gateway全局GlobalFilter获取请求参数
Spring Cloud Gateway全局GlobalFilter获取请求参数
4
Windows平台搭建Kafka在和简单示例
Windows平台搭建Kafka在和简单示例
5
CentOS下安装MongoDB
CentOS下安装MongoDB
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。