小程序 一个function无法正常调用另一个function;Cannot read property ‘xxx‘ of undefined

一个function无法调用另一个function看看这里

 var that = this
      wx.getLocation({
        type: 'wgs84',
        success:function (res) {
          that.setData({
            location_id:res.longitude+','+res.latitude
            
          })
        },
        
       })
       that.click() //无法调用

报错:

Cannot read property ‘text’ of undefined;at pages/weather/weather onLoad function;at api request success callback function TypeError: Cannot read property ‘text’ of undefined
在这里插入图片描述
就是说属性text没有声明,肯定是申明的。at api request success callback function 这里说明是在这里没有申明。然后我的直觉是生命周期的问题,因为我人工模拟调用都能成功,然后我去查找官方文档。

原因

在这里插入图片描述
然后就找到原因了。它这要结束回调才能正常使用另一个function。

解决方法:将上面的代码修改如下

onLoad: function (options) {
      //console.log("load")
      var that = this
      wx.getLocation({
        type: 'wgs84',
        success:function (res) {
          that.setData({
            location_id:res.longitude+','+res.latitude
            
          })
        },
        complete:function(e){
          that.click()
        }
       })
       
    },

微信官方文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值