【问题标题】:.Firebase read data in kotlin.Firebase 在 kotlin 中读取数据
【发布时间】:2020-10-07 00:02:56
【问题描述】:

嗨,当我尝试在文档引用中获取数据时,它给了我 For-loop range must have an 'iterator()' method error while using in for loop。我猜它看起来像 DocumentSnapshot!。 据我所知,它应该是 MutableList。但我不确定。

    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) {
                    }
                }
            }
        }
    }
}

【问题讨论】:

    标签: android firebase kotlin google-cloud-firestore


    【解决方案1】:

    document 将成为 DocumentSnapshot 对象。它不能使用 for 循环进行迭代。

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

    【讨论】:

    • 如何使用带有 kotlin 的 firebase 执行?
    猜你喜欢
    • 1970-01-01
    • 2020-07-08
    • 2019-09-26
    • 2021-11-07
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    相关资源
    最近更新 更多