【发布时间】:2020-10-03 07:42:40
【问题描述】:
在this code snippet 中,从 Firestore 中检索数据:
val docRef = db.collection("cities").document("BJ")
docRef.get().addOnSuccessListener { documentSnapshot ->
val city = documentSnapshot.toObject<City>()
}
我怎样才能把它变成一个函数,返回一个城市对象?像这样的:
fun getCity(): City?{
val docRef = db.collection("cities").document("BJ")
docRef.get().addOnSuccessListener { documentSnapshot ->
val city = documentSnapshot.toObject<City>()
return city
}
当我调用 getCity() 函数时,我能以某种方式“等待”结果吗?
【问题讨论】:
标签: firebase kotlin google-cloud-firestore