新手问题,如何显示当前经纬度在<text>

发布于 8 年前作者 junshi2679 次浏览最后编辑 8 年前来自 ask

我想把wx.getLocation获得的经纬度填在<text class=“log-item”>{{address}}</text>里面,

在回调函数中this.setData({ address: addr})这样写诗错的,请指正,该如何写?


<view class=“container log-list”>

    <text class=“log-item”>{{address}}</text>

</view>

Page({
   
  onLoad: function () {
    
 
    wx.getLocation({
      success: function (res) {
        var latitude = res.latitude // 经度
        var longitude = res.longitude // 纬度
        var addr = "latitude=" + latitude + ",longitude" + longitude
        console.log(addr)
        //这里出错了,应该是this的问题,但如何表达呢?
        this.setData({ address: addr})
      },
    })
 
  }
1 回复
yan41
yan411 楼6 年前

外面 var that=this 然后 that