蓝牙获取的列表 添加修改数据 会有丢失
发布于 7 年前 作者 juanren 11596 次浏览 来自 问答

// 获取已发现的蓝牙设配

getBluetoothDevices() {

var that = this;

wx.getBluetoothDevices({

success(res) {

that.stopBluetoothDevicesDiscovery()

wx.hideLoading()

console.log(res.devices, ‘发现的蓝牙设配成功’)

for (var key in res.devices) {

res.devices[key].active = false

}

that.setData({

lanyanlist: res.devices,

isbnt: true

})

},

fail(err) {

console.log(err, ‘发现的蓝牙设配失败’)

},

complete(data) {

console.log(data, ‘发现的蓝牙设配完成’)

}

})

},

//修改数据

addsuo(e) {

var that = this;

var index = e.currentTarget.dataset.index

var name = `lanyanlist[${index}].name`

this.setData({

[name]: ‘chengwen’

})

},

lanyanlist数组 数据会丢失

// 模板传参

lanyanlist: [{

name: ‘蓝牙1’,

deviceId: “71:00:8B:32:26:CC”,

RSSI: -60

}, {

name: 蓝牙2,

deviceId: “71:00:8B:32:26:CC”,

RSSI: -60

}, {

name: 蓝牙3,

deviceId: “71:00:8B:32:26:CC”,

RSSI: -60

}, {

name: 蓝牙4,

deviceId: “71:00:8B:32:26:CC”,

RSSI: -60

}],

//修改数据

addsuo(e) {

var that = this;

var index = e.currentTarget.dataset.index

var name = `lanyanlist[${index}].name`

this.setData({

[name]: ‘chengwen’

})

},

这样子修改又没问题 是什么原因?

回到顶部