小程序的开发记录

获取或设置data里的值

this.data.name   //不同于vue,要加一个data

this.setData({
      name: 'bill gates'
    })

js文件里定义函数和调用函数

getCart: function () {
    //具体函数代码
}

//调用
var that = this;
that.getCart();

绑定事件,获取事件参数

index.wxml:

<view class="btn btn1" bindtap="btnComfirm"  data-goodsid="{{goodsId}}">确认</view>

index.js:

btnComfirm(e) {
    let goodsId= e.currentTarget.dataset.goodsid; //获取goodsid的值
}

给数组里的每个对象增加一个字段

arrray.forEach(item => {
          item.qty=0; //增加的字段
        })
原文地址:https://www.cnblogs.com/bqh10086/p/12620804.html