微信小程序 setData动态设置数组中的数据
生活随笔
收集整理的這篇文章主要介紹了
微信小程序 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 = thiswx.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.85that.data.controls[1].position.top = (res.windowHeight)*0.85that.data.controls[0].position.left = (res.windowWidth) * 0.27that.data.controls[1].position.left = (res.windowWidth) * 0.54that.setData({UserSystemInfo:res,controls: that.data.controls})}})}大功告成!愿每一個工程師在開發的道路上少一些坎坷。。。愿世界和平!hiahia~~~
總結
以上是生活随笔為你收集整理的微信小程序 setData动态设置数组中的数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Django使用Mysql时数据库配置
- 下一篇: Https 与 SSl证书 概要