Swift iOS:Firebase分页
发布时间:2020-12-14 05:46:21 所属栏目:百科 来源:网络整理
导读:我有这个Firebase数据: 我想通过分页查询帖子数据.目前我的代码正在将此JS代码转换为Swift代码 let postsRef = self.rootDatabaseReference.child("development/posts")postsRef.queryOrderedByChild("createdAt").queryStartingAtValue((page - 1) * count
我有这个Firebase数据:
我想通过分页查询帖子数据.目前我的代码正在将此JS代码转换为Swift代码 let postsRef = self.rootDatabaseReference.child("development/posts") postsRef.queryOrderedByChild("createdAt").queryStartingAtValue((page - 1) * count).queryLimitedToFirst(UInt(count)).observeSingleEventOfType(.Value,withBlock: { snapshot in .... }) 访问时,此数据页:1,计数:1.我可以获取“posts.a”的数据但是当我尝试访问页面时:2,计数:1返回仍然是“posts.a” 我在这里想念的是什么?
假设您在将数据推送到Firebase时正在或将要使用childByAutoId(),您可以使用queryOrderedByKey()按时间顺序排序数据. Doc
here.
要启动特定键,您必须使用queryStartingAtValue(_ :)附加查询. 样品用法: var count = numberOfItemsPerPage var query ref.queryOrderedByKey() if startKey != nil { query = query.queryStartingAtValue(startKey) count += 1 } query.queryLimitedToFirst(UInt(count)).observeSingleEventOfType(.Value,withBlock: { snapshot in guard var children = snapshot.children.allObjects as? [FIRDataSnapshot] else { // Handle error return } if startKey != nil && !children.isEmpty { children.removeFirst() } // Do something with children }) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |