setting data field "xx" to undefined is invalid问题?

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

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

2 回复
guiyingcai
guiyingcai1 楼5 年前

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)
    })
  })
}
fmeng
fmeng2 楼4 年前

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