微信小程序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 深度学习基础:线性代数(4)_范数
深度学习基础:线性代数(4)_范数
2
RadioButton在Android 4.4及以下调用setButtonDrawable(null)无效的问题
RadioButton在Android 4.4及以下调用setButtonDrawable(null)无效的问题
3
Magento模式设置
Magento模式设置
4
Vuex状态监听mapState与普通的局部计算属性混合使用
Vuex状态监听mapState与普通的局部计算属性混合使用
5
CentOS 7 利用crontab定时执行任务
CentOS 7 利用crontab定时执行任务
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。