アプレット wx:for wx:for-index data-xxx
wx:for="{ {list}}" //リストはループする配列です
wx:for-items="{ {list}}" //list はループされる配列です。for と同じです。
wx:for-item="item" //item は各アイテムを表すオブジェクトです
wx:key="{ {index}}" //配列を走査するための一意の識別子として
wx:for-index="{ {fc}}" //'現在の要素を指す添え字名です。他のイベントでカスタム イベントを定義できます (data-xxx='{{fc}}'、 カスタムパラメータ e) の下に属性を出力して添え字を取得できます。
wx:for-index="{ { {変数名}}" と data-xxx='{ { {変数名}}' が一緒に使用され、最後に添え字が e.currentTarget.dataset.xxx を通じて取得されます。
wxml
<view class="scroll-view">
<view class="" wx:for="{
{list}}" wx:for-index="index" bindtap="timeChange" data-index='{
{index}}'>{
{item}}</view>
</view>
js
timeChange: function (e) {
var that = this
//console.log( e.currentTarget.dataset)
let index = e.currentTarget.dataset.index + 1
this.setData({
timeIndex: e.currentTarget.dataset.index
})
console.log(index)
},