<view wx:for="array" wx:for-index="idx" wx:key bindtap="bbb">
{{idx}}: {{itemName.message}}
</view>
页面是有显示idx的值但是为啥e获取不到这个idx
bbb(e){
console.log(e)
},
{type: "tap", timeStamp: 19646, target: {…}, currentTarget: {…}, mark: {…}, …}
changedTouches: [{…}]
currentTarget: {id: "", offsetLeft: 0, offsetTop: 20, dataset: {…}}
detail: {x: 38, y: 32}
mark: {}
mut: false
target: {id: "", offsetLeft: 0, offsetTop: 20, dataset: {…}}
timeStamp: 19646
touches: [{…}]
type: "tap"
__proto__: Object
array是你的数组数据的话,要这样写wx:for="{{array}}"
其次,要想获取这个idx,你要加个data-idx="{{idx}}",然后就可以e.currentTarget.dataset.idx获取idx的值
需要自定义绑定一个属性 data-*** ,在点击事件获取 e.currentTarget.dataset.***
你可以好好再看看文档
wx:for="{{array}}" 要这样写的吧