WXML:
<block wx:for="{{nums}}" wx:for-index='key' wx:for-item='item'> <view class="maxbox" bindtap="imgchange" id="{{key}}"> <text class="nums">{{item.num}}</text> </view> </block>
JS:
Page({ data: { nums:[ {num:11}, {num:22} ] }, imgchange: function (event) { //获取当前item的下标id 通过currentTarget.id var id = event.currentTarget.id; console.log(id); var nums = this.data.nums[id].num; console.log(nums); }, })