今天小程序開發過程中,遇到了這個棘手的問題。由於我沒有前端基礎,只是知道一點兒基本的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 })有問題或者其他見解,歡迎交流討論。
方法參考自:

