微信小程序 setData动态设置数组中的数据
现在有一组死数据
但是想在使用时动态修改其中的值
在setData中不能直接设置,真想。。。。。。,算了是这个和谐的社会救了那个工程师。
接下来,我们去征服她!
死数据:
//地图上方控件 controls: [ { id: 1, iconPath: "../image/jiuyuan.png", position: { left: 85, top: 450-50, width: 70, height: 50 }, clickable: true }, { id: 2, iconPath: "../image/jiuzhu.png", position: { left:165, top: 450 - 50, width: 70, height: 50 }, clickable: true }, ],我的设计初衷是让这两个图标始终在手机屏幕距离顶部85%的位置
所以我需要在获取到手机的屏幕相关信息之后动态设置position中left和top 的值
人狠话不多,直接上代码!
//获取用户手机相关信息 getUserSystemInfo:function(){ var that = this wx.getSystemInfo({ success: function (res) { console.log("手机型号"+res.model) console.log(res.pixelRatio) console.log(res.windowWidth) console.log(res.windowHeight) console.log(res.language) console.log(res.version) //更新数据 console.log(that.data.controls) that.data.controls[0].position.top = (res.windowHeight) * 0.85 that.data.controls[1].position.top = (res.windowHeight)*0.85 that.data.controls[0].position.left = (res.windowWidth) * 0.27 that.data.controls[1].position.left = (res.windowWidth) * 0.54 that.setData({ UserSystemInfo:res, controls: that.data.controls }) } }) }
大功告成!愿每一个工程师在开发的道路上少一些坎坷。。。愿世界和平!hiahia~~~
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 微信小程序循环赋值坑
- 下一篇: Yii2.0 删除数据(CRUD)