微信小程序怎么pe修改数据

微信小程序怎么pe修改数据,第1张

项目需求大概是这样的一个流程,当用户点击“选为当前设备”,点击的那个按钮变为 灰色按钮且展示的文字是“当前设备”,其他的按钮展示成“选为当前设备”,且按钮成绿色状态

本地缓存数据如下:

deviceList:[

{deviceName:'设备A',deviceId:'a',selStatus:false},

{deviceName:'设备B',deviceId:'b',selStatus:false},

{deviceName:'设备C',deviceId:'c',selStatus:true}

]

1

2

3

4

5

1

2

3

4

5

现在将设备A项选为当前设备:

index.wxml:

<view class="device-list" wx:for="{{deviceList}}" wx:for-item="item" wx:key="item">

<view class="device_name">{{item.deviceName}}</view>

<button bindtap="setCurDevice" data-id="{{item.deviceId}}" disabled="{{item.selStatus ? true : false}}"

class="selectCur" type="{{item.selStatus ? 'default' : 'primary'}}">{{item.selStatus ?'当前设备':'选为当前设备'}}</button>

</view>

1

2

3

4

5

1

2

3

4

5

index

在缓漏一些场景中,我们需要获取到标签里面的塌裤值团哪简来和接口返回的值做对比,一致则进行下一步,后者进行错误判断

<block wx:for='{{objectArray}}'  data-name='{{item.name}}' data-id='{{item.id}}' bindtap='select'>

        <text class='yuzhong'>{{item.name}}</text>

    </view>

主要在于 data- 这个上面  上面的那个name 和 id 是我自己定义的,你们可以随意定义一些语义化的词,

获取也很简单:

select:function(e){

console.log(e.currentTarget.dataset.name)

    },

您好,可以这样设置:

function setData(){

    var that = this

  弯伍  that.setData({

      smart_cookies_city:'134',

    做顷  cityname:'南京'埋胡或

    })

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12569269.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存