setData()失效?
发布于 7 年前 作者 yan89 12547 次浏览 来自 问答
  markertap: function(e) {
    var that = this;
    var id;
    var temp = false;
    var pindex;
    if (typeof(e) != undefined && typeof(e) == "string") {
      //分类tab跳转
      id = e;
      temp = true;
    } else if (typeof(e.markerId) != undefined) {
      //气泡点击
      id = e.markerId;
    }
    for (var i = 0; i < that.data.markers.length; i++) {
      if (that.data.markers[i].id == id) {
        pindex = i;
        break;
      }
    }
    //图标变回
    if (that.data.detailPId != -1 && pindex != that.data.detailPId) {
      that.changeMarker(false, that.data.markers, that.data.detailPId, that.data.project)
    }
    wx: wx.request({
      url: 'https://www.s**h.com/project/form/' + id,
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: 'post',
      success: function(res) {
        if (res.statusCode == 200) {
          that.setData({
            project: res.data.data,
            flag: false,
            markers: that.changeMarker(true, that.data.markers, pindex, res.data.data),
            detailPId: pindex
          })
          if (temp) {
            that.setData({
              scale: 17,
              latitude: res.data.data.coordinates.split(",")[1],
              longitude: res.data.data.coordinates.split(",")[0]
            })
          }
        }
      },
    });
    that.getPictures(id).then(function (result) {
      console.log(result)//该部分打印返回值成功 但是无法set成功值
      if (result.datas.length < 1) {
        that.setData({
          pictures: result.datas,
          fullPictures: that.getFullPictures(result.datas),
          height: "48%"
        })
      } else {
        that.setData({
          pictures: result.datas,
          fullPictures: that.getFullPictures(result.datas),
          height: "75%"
        })
      }
    })
  },
打印结果

同时该方法结束后AppData中的该值未发生变化

1 回复

你好,请仔细检查代码。若还有问题建议提供能复现问题的代码片段,方便大家帮忙定位问题(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部