如何将总计数传递给pageInfo中的客户端 [英] How to pass total count to the client in pageInfo
问题描述
我使用first
after
和last
before
进行分页.
hasNextPage
和hasPreviousPage
非常有用.
I use first
after
and last
before
to do pagination.
hasNextPage
and hasPreviousPage
are very useful.
但是我还需要total count
,这样我才能在客户端上计算并显示page 5 of 343 pages
之类的东西.
But what I need is also the total count
so that I can calculate and show things like page 5 of 343 pages
on the client.
不幸的是,即使我在服务器站点上有此信息,它也不是pageInfo
的一部分.
Unfortunately that is not part of pageInfo
even though I have the information on the server site.
能否请您在pageInfo
中包含一个total
字段,并扩展connectionFromArray
来像connectionFromArraySlice
那样容纳全部arrayLength
?
Can you please include a total
field in the pageInfo
and extend connectionFromArray
to take in the total arrayLength
like connectionFromArraySlice
already does?
谢谢
推荐答案
pageInfo
旨在表示有关特定页面的信息,而项的总数实际上是连接本身的属性.我们建议将count
字段添加到连接中.您可以使用以下查询它:
pageInfo
is designed to represent information about the specific page, whereas the total number of items is really a property of the connection itself. We recommend adding a count
field to the connection. You might query it with:
fragment on TodoList {
tasks(first: 10) {
count # <-- total number of tasks
edges { ... }
pageInfo { ... }
}
中继在连接上支持任意字段,因此可以随意命名为count
,totalCount
等.
Relay supports arbitrary fields on a connection, so you're free to name this count
, totalCount
, etc.
这篇关于如何将总计数传递给pageInfo中的客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!