1.当我们编译微信小程序时,可能会出现我们想确定某个位置,需要用到的参数
在js文件中
choise(e){
console.log(e)
let index=e.currentTarget.dataset.index
let serviceId=this.data.services[index].uuid
this.setData({
serviceId:serviceId
})
wx.getBLEDeviceCharacteristics({
// 这里的 deviceId 需要已经通过 wx.createBLEConnection 与对应设备建立链接
deviceId:this.data.deviceId,
// 这里的 serviceId 需要在 wx.getBLEDeviceServices 接口中获取
serviceId:this.data.serviceId,
success (res) {
console.log(‘device getBLEDeviceCharacteristics:’, res.characteristics)
},
})
},
在wxml中
服务值:{{service.uuid}}
在这里我遇到了困扰我很久的问题,就是当我按下选择键后报错,告诉我uuid没有定义,其实不是我没有定义,而是因为我的index并没有选择,当我一句一句分析时就发现在e.currentTarget.dataset.index里面为空,这是因为我在wxml里面缺少致命的一项data-index="{{index}}",导致我里面为空,一直报错