How does the applet obtain the information of the clicked row in the wx:for list?

1. If you want to get the index of the clicked row (that is, the index of the for loop array )

<view class='chooseTitle'>
    <view class='choose' wx:for="{
   
   {monArray}}" wx:for-index="bindex" wx:key="item.id">
      <view class="itemName" bindtap='switchTab' data-bindex='{
   
   {bindex}}' data-id='{
   
   {item.id}}'>{
   
   {item}}</view>
    </view>
  </view>

JS code: 


switchTab: function (e) {
    console.log(e)
    var index = parseInt(e.currentTarget.dataset.index)
}

2. If you want to get more detailed information about the clicked row 


<view class="weui-cells searchbar-result" wx:if="{
   
   {inputVal.length > 0}}" hidden="{
   
   {!resultShowed}}">
          <view wx:for="{
   
   {uplink}}" wx:for-item="item" wx:key="item.id" >
            <navigator url="" class="weui-cell" hover-class="weui-cell_active" data-item='{
   
   {item}}' data-id="item.id" bindtap="queryBtnClick">
              <view class="weui-cell__bd">
                  <view>{
   
   {uplink[index].name}}:{
   
   {uplink[index].text}}->{
   
   {downlink[index].text}}</view>
              </view>
            </navigator>
          </view>
        </view>
    </view>

 JS code:

queryBtnClick: function (e) {
    console.log("click", e)
    var clickitem = e.currentTarget.dataset.item
}

 

 

Guess you like

Origin blog.csdn.net/weixin_44266024/article/details/128241596