[英]Loading small amounts of data from Lumen API time
I have an API built in lumen and I plan to consume the API json response in the frontend using a single page framework like Angular.我有一个内置流明的 API,我计划在前端使用 ZC3DE1C338BADD378 之类的单页框架使用 API json 响应
The problem is the response from some routes contain huge amount of data which is aprox 50000 rows as of now.问题是某些路由的响应包含大量数据,截至目前大约有 50000 行。 I intend to send the data to the frontend in small portion depending on how much the user is using.
我打算根据用户的使用量将数据一小部分发送到前端。
for example on a social site you get small chunks of posts loaded at a time and as you scroll down more post are loaded until you eventual close the application
例如,在社交网站上,您一次加载一小部分帖子,当您向下滚动时,会加载更多帖子,直到您最终关闭应用程序
I would like my API to do something similar.我希望我的 API 做类似的事情。 Alternatives that I have considered are
我考虑过的替代方案是
What options do I have for achieving this and also is there a workaround on the options I mentioned above?我有什么选择来实现这一点,还有我上面提到的选项的解决方法吗?
THANK YOU谢谢你
So, since the Paginate method does exactly what you need , you will need to use it.因此,由于 Paginate 方法完全符合您的需要,因此您将需要使用它。 Implement an API function that will receive a starting point and an offset on the server-side.
实现一个 API function,它将在服务器端接收一个起点和一个偏移量。
On the client-side you do not have to display paging controls.在客户端,您不必显示分页控件。 You can instead implement a
scroll
event and detect if the scrolling reached the bottom .您可以改为实现
scroll
事件并检测滚动是否到达底部。 If so, then trigger a function
(still in JS on the client-side), that will ask for the next packet of data.如果是这样,则触发
function
(仍在客户端的 JS 中),它将请求下一个数据包。 For this purpose, you will always need to know/find out how many records were already loaded and send that number as the starting point and your offset to the API function
we have discussed above.为此,您总是需要知道/找出已经加载了多少记录,并将该数字作为起点和您的偏移量发送到我们上面讨论过的 API
function
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.