在使用wx.request的success回调函数中作用域的问题

 wx.request({
      url: config.projectUrl + '/applets/getGoodsByGoodId',
      data: {
        goodId: goodId,
      },
      method: 'GET',
      header: {
        'content-type': 'application/json' //默认值
      },
      success:function(e){
        var myLocationlatitude;
        var myLocationlongitude;
        var shop = e.data.shop;
        var good = e.data.good;
        //获取用户位置
        wx.getLocation({
          success: function (res) {
            myLocationlatitude = res.latitude,
            myLocationlongitude = res.longitude
          },
          fail: function () {
            console.log("2处调用位置失败");
          }
        })
        var markers = [
          {                          //自己位置markers
            iconPath: '/img/我的位置.png',
            id: 0,
            latitude: myLocationlatitude,
            longitude: myLocationlongitude,
            width: 50,
            height: 50,
            callout: {
              content: "我的位置",
              color: "#FF0000",
              fontSize: 15,
              borderRadius: 5,
              bgColor: "#FFFFFF",
              display: "ALWAYS",
              padding: 5,
              textAlign: "center"
            }
          },
          {
            //iconPath: '/img/01.jpg',
            id: 1,
            latitude: shop.latitude,
            longitude: shop.longtitude,
            width: 20,
            height: 35,
            callout: {
              content: good.name,
              color: "#000000",
              fontSize: 15,
              borderRadius: 5,
              bgColor: "#FFFFFF",
              display: "ALWAYS",
              padding: 5,
              textAlign: "center"
            }
          }
        ]

描述:

1.好像只在wx.,request中success才遇到,也就是e,data的值不能赋值给success函数之外定义的值,外面的值接收不到!!!

2.wx.getLovation中e好像赋值给外面的值可以接收到。

3.在onLoad()初始化函数中先执行赋值,输出等简单的操作才会执行wx.getLocation,wx.request之类的函数。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值