微信小程序怎么 点击获取循环中的内容获取?

点击获取到对应的数组内容

数组结构:

{
    date: "2018-03-13",
    z_num: "450",
    m_num: "6",
    money: "3956.67",
    id: 13,
    line: [{
        placeholder: "在线收益",
        item_unm: "2000.60",
        num: 1
    }, {
        placeholder: "现金收益",
        item_unm: "400.00",
        num: 1
    }, {
        placeholder: "退款金额",
        item_unm: "1565.07",
        num: 1
    }]
},

js:

bindDate:function(e){
    var that = this;
    var datas = that.data.datas;
    var id = e.currentTarget.dataset.id;
    for (let i in datas){
      var datdId = datas[i][id].line;
      that.setData({
        line: datdId
      })
    }
    console.log(id);
    that.getTotalPrice();
},
阅读 4.8k
3 个回答

可以通过data- 属性把数据通过点击事件一起传过去。
也是通过传个index,找到对应数据!

http://callmesoul.cn/

wx:for
<view data-index='{{index}}' data-value='{{item.placeholder}}>

</view>
index 索引 传值可以传Array或是Object等 类型

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题