<button bindtap="startSao" type="primary">开始扫描</button>
<button bindtap="stopDiscovery" type="primary">停止搜索设备</button>
<button bindtap="connectToDevice" data-device-id="{
{device.deviceId}}">连接</button>
<view wx:for="{
{list}}" wx:for-item='deviceID' wx:for-index='index'>
{
{deviceID}}
<text wx:if="{
{index < list.length - 1}}">, </text>
</view>
// index.js
Component({
data: {
list:[],
},
methods: {
// 事件处理函数
startSao:function(){
var that=this;
wx.openBluetoothAdapter({
success (res) {
wx.