微信小程序用setData更新数组里的值

时间:2020-12-18 16:53:31   收藏:0   阅读:62
假设在data中定义了一个数组markers
markers: [{
      title: "",
      id: "",
      latitude: "",
      longitude: "",
      iconPath: "img/Local.png",
      width: 20,
      height: 20
    }]
如果我现在要用setData修改latitude和longitude的值,首先先定义两个变量,将要修改的值赋值给这两个变量(注意要加引号)
 var lat = "that.markers[0].lat";
 var lng = "that.markers[0].lng";

然后在setData中赋值(注意加中括号)

that.setData({
          //经纬度赋值
          [lat]:res.latitude,
          [lng]:res.longitude
        })

 

原文:https://www.cnblogs.com/16WSH/p/14155409.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!