数据呈现是这样的,怎么在页面上点击Stewardess,就能打印它,我获取的都是其中数组
<block wx:for="{{DataList}}" wx:key="index" wx:for-index="myIndex">
<view class="aa">
<view class="bb">{{item.date}}</view>
<block wx:for="{{item.data}}" wx:key="index2" wx:for-item="data" wx:for-index="mySubIndex">
<view wx:for="{{data}}" wx:key="index3" wx:for-item="itm">
<text class="cc" bindtap="transfer" data-index="{{myIndex}}" data-subindex="{{mySubIndex}}">{{itm}}</text>
<!-- <text class="cc" bindtap="transfer" data-index="{{myIndex}}" data-subindex="{{mySubIndex}}">{{data}}</text> -->
</view>
</block>
</view>
</block>
// 这是数据
DataList=[{"date":"2023-05-26","data":[["dust","gang","mechanic"],["refuge","stewardess"]],
//transfer函数获取指定单词
transfer(event) {
const index = event.currentTarget.dataset.index;
const subIndex = event.currentTarget.dataset.subindex;
const element = this.data.DataList[index].data[subIndex];
console.log(event.currentTarget.dataset)
console.log(element); //["refuge","stewardess"] 我想得到是stewardess
}
再把这一层<view wx:for="{{data}}" wx:key="index3" wx:for-item="itm">
对应的index也放进text.cc的dataset里面去,然后js里面
const element = this.data.DataList[index].data[subIndex][xxxIndex]
我也有这样的需求,我试试