微信小程序事件傳參

詳細可以參考官方文檔

https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html#%E4%BA%8B%E4%BB%B6%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F

簡單來說,在wxml中通過 data-… 來綁定屬性, 這裏我用了data-id

<view class="itemBox" wx:for="{{notices}}">
	<view class="title" bindtap="noticePage" data-id="{{item.id}}">{{item.title}}</view>
</view>

在js文件中 通過 detail.currentTarget.dataset[ ’ … '] 來獲取 dataset[ ‘id’] 中的id和wxml中我們寫的data-id是對應的

  noticePage:function(detail){
      console.log( detail.currentTarget.dataset['id']);
  },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章