小程序获取列表的下标
生活随笔
收集整理的這篇文章主要介紹了
小程序获取列表的下标
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
wxml獲取:wx:for-index="index"
<block wx:for="{{listData}}" wx:for-index="index" ><view class="td XH" style="width: 100rpx;"> {{index+1}}</view>js獲取:data-index='{{index}}'
<block wx:for='{{items}}'><view class='cell' data-index='{{index}}' bindtap='click_anniu'>{{item.value}}</view></block>?
Page({data: {items: [{ name: 'USA', value: '美國' },{ name: 'CHN', value: '中國', checked: 'true' },{ name: 'BRA', value: '巴西' },{ name: 'JPN', value: '日本' },{ name: 'ENG', value: '英國' },{ name: 'TUR', value: '法國' },]},click_anniu: function (e) {let index = e.currentTarget.dataset.index;console.log("index----->" + JSON.stringify(index));} })?
總結
以上是生活随笔為你收集整理的小程序获取列表的下标的全部內容,希望文章能夠幫你解決所遇到的問題。