gpt4 book ai didi

swift - 一起使用 queryEqual 和 queryEnding 吗?

转载 作者:行者123 更新时间:2023-11-30 10:24:57 25 4
gpt4 key购买 nike

我正在尝试按“流派”:“艺术与人文”进行查询,但还需要 queryEnding 根据时间戳对我的数据进行分页。

但是,我们不能在 Xcode 中组合使用它们。还有什么方法呢?

这就是我正在尝试的:(不起作用)

queryRef = ref.queryOrdered(byChild: "genre").queryEqual(toValue: "Arts & Humanities").queryEnding(atValue: lastTimestamp)

这是我用来对数据进行分页的代码。工作正常,但我无法仅使用“艺术与人文”的数据对分页进行排序。这将对我的整个提要进行分页。

        var queryRef:DatabaseQuery
let lastPost = self.postList.last


if lastPost != nil {
let lastTimestamp = lastPost!.createdAt.timeIntervalSince1970 * 1000

queryRef = ref.queryOrdered(byChild: "timestamp").queryEnding(atValue: lastTimestamp)

} else {
queryRef = ref.queryOrdered(byChild: "timestamp")

}

最佳答案

您可以将 queryOrderedqueryEqual 一起使用:

queryRef = ref.queryOrdered(byChild : "genre").queryEqual(toValue : "Arts & Humanities")

然后使用observe方法检索数据,这将检索具有genre = Arts & Humanities的数据,然后在监听器内创建另一个查询,这次您只使用 queryEnding 方法并附加另一个监听器来根据查询检索数据。

关于swift - 一起使用 queryEqual 和 queryEnding 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60131229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com