setting data field "xx" to undefined is invalid问题?
发布于 4 年前 作者 li21 9123 次浏览 来自 问答

如图,方法返回值里面显示有值,但是在wx.getlocation()调用里返回值的时候就会返回undefined

2 回复

getFalseDataLocations 函数体内没有 return,返回的是 undefined;写在 db.get.then 里面的 return 只是作为回调函数的返回值,不会变成 getFalseDataLocations 的返回值,应该这样写

that.getFalseDataLocations().then(markers => {
  that.setData({
    ...
    markers
  })
})

getFalseDataLocations() {
  return new Promise(resolve => {
    ...
    db.collection...
    .get().then(res => {
      ...
      resolve(myMarker)
    })
  })
}

确认下这个函数的返回结果不是异步的

回到顶部