zoukankan      html  css  js  c++  java
  • 微信小程序中如何获取for循环的item相关值到JS页面的问题

    今天小程序开发过程中,遇到了这个棘手的问题。由于我没有前端基础,只是知道一点儿基本的HTML标签,所以卡了好久,特此分享,望后来的你,可以有所收获。

    measure 

    step 1  *.WXML: 在view中用变量id,将item的索引存起来

    1 <block wx:for="{{info}}" wx:for-index="item_id" wx:for-item="item_key">
    2     <!--bindtouch函数绑定触摸弹出账号密码-->
    3       <view class='infoBack' bindtouchstart='touchShow' id="{{item_id}}"> <!--先获取id-->
    4         <text>{{item_id+1}} - {{item_key}}</text>
    5       </view>
    6     </block>

    step 2  *.JS: 在绑定的事件中通过e.currentTarget.id,来获取该id,再用id索引到对应数组中取出相关value。

    1 var i = e.currentTarget.id
    2       this.setData({
    3         cur_key : this.data.info[i]
    4       })

    有问题或者其他见解,欢迎交流讨论。

    方法参考自:

  • 相关阅读:
    203. Remove Linked List Elements
    86. Partition List
    143. Reorder List
    876. Middle of the Linked List
    246. Strobogrammatic Number
    202. Happy Number
    数据类型转换
    表达式
    面向对象
    对齐
  • 原文地址:https://www.cnblogs.com/yocichen/p/10349339.html
Copyright © 2011-2022 走看看