How does WeChat Mini Programs click to get the content in the loop?

Click to get the corresponding array contents

Array structure:

{
    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();
},

you can pass the data through the click event through the data- attribute.
also finds the corresponding data by passing an index,!

http://callmesoul.cn/


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

< / view >
index index can pass values of types such as Array or Object


https://github.com/Liuniuliu/.

has been put into github

Menu