.Firebase读取kotlin中的数据



嗨,当我试图在文档引用中获取数据时,它给了我For循环范围在使用in For循环时必须有一个"迭代器(("方法错误。我想它看起来像DocumentSnapshot!。正如我所知,它应该是MutableList<DocumentSnapshot>。但我不确定。

fun firebase_read() {
if (mAuth.currentUser != null) {
val schedule_document = databsae.collection("schedules").document(mAuth.currentUser!!.phoneNumber.toString())
schedule_document.get().addOnSuccessListener { document ->
if (document != null) {
for (i in document) {
}
}
}
}
}
}

document将成为DocumentSnapshot对象。它不可与for循环一起迭代。

如果您试图迭代文档中的字段,可以调用document.getData((,并像迭代Kotlin中的任何其他Map一样迭代返回的Map。

最新更新