<view class="upload" tt-for="{{ items }}" tt:for-item="item" tt:for-index="itemIndex">
<view class="image" data-value="{{itemIndex}}" bindtap="uploadImage">
<image tt:if="{{!imageArr[itemIndex].imageUrl.length}}" src="https://cdn2.blankme.com/static/after_sale/上传图片.png" mode="scaleToFill" />
<image style="width: 100%;height: 100%;" tt:else src="{{imageArr[itemIndex].imageUrl[0]}}" mode="scaleToFill" />
</view>
<text>{{ item.optionTitle }}</text>
</view>
uploadImage(e) {
console.log(e)
console.log(e.target.dataset.value)
console.log(this.data.imageArr[e.target.dataset.value])
},
循环中指定索引值和循环值,点击方法中取当前点击元素所在索引值。
有时候能拿到值,有时候就是 undefined 。
请问是什么问题呢 ?