微信小程序数据操作(增、删、改、查),id为随机数

微信小程序数据操作(增、删、改、查),id为随机数

 

addItem() {

    let that = this

    var math = Math.floor(Math.random() * 50 + 10)

    var dataList = that.data.dataList

    var dataBean = {

      name: '添加时间',

      id: math

    }

    dataList.push(dataBean)

    that.setData({

      dataList: dataList

    })

  }

微信小程序数据操作(增、删、改、查),id为随机数

Math.random() * 50 取0到50的一个随机数

Math.random() * 50 + 10  取0到50的一个随机数

Math.floor(Math.random() * 50 + 10)  取整数

微信小程序数据操作(增、删、改、查),id为随机数