如何使用Query Cursor跳转到特定页面? [英] How to jump to specific page using Query Cursor?

查看:181
本文介绍了如何使用Query Cursor跳转到特定页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python(webapp2)开发我的网站,并在后端开发Google数据存储。
我已经添加了查询光标分页,它的工作很好,但它只有下一个和以前的功能分页,问题是,我将如何跳转到特定页面,如我在页面1,我想跳转到页面3,我将如何管理它在查询光标?



我也访问过下面的链接,但没有找到任何解决方案



https://cloud.google.com/appengine/docs/standard/python/datastore/query-cursors

解决方案

你不行。数据存储不知道查询结果的数量。



然而,您可以使用一些技巧来模拟完整的分页。
例如,一种技术是在循环中生成一定数量的游标并生成最后一页。



 (results,next_curs,more)= model.query .... fetch_page(...)

for xrange(5):
#为页码'b'生成光标
#使用前一页中的next_cursor
(results,next_curs,more)= model ..... fetch_page(cursor = next_cursor,...)

由于您不访问结果游标的性能可以接受(取决于模型的复杂性,查询的复杂性等)。
您可以调整您的数据。


I am developing my website in python(webapp2) and google data store in back end. I have added query cursor for pagination and it's working good but it has only next and previous functions for pagination, the question is that how i will jump to specific page like i am on page 1 and i want to jump to page 3, how i will manage it in Query Cursor?

i have also visited below links but didn't find any solution https://www.the-swamp.info/blog/pagination-google-app-engine/

https://cloud.google.com/appengine/docs/standard/python/datastore/query-cursors

解决方案

You can't. Datastore doesn't know the number of results found by your query.

You can however use some tricks to simulate a full pagination. For example one technique is to generate a certain number of cursors in a loop and generating the "last page" one.

Like in the following pseudo-code:

(results, next_curs, more) = model.query....fetch_page(...)

for p in xrange(5):
    # generate cursor for page number 'b' 
    # by using the next_cursor from previous page
    (results, next_curs, more) = model.....fetch_page(cursor=next_cursor,...)

As you don't access the results cursor the performance is somewhat acceptable (depending on your models complexity, query complexity and such). You can tweak it on your data.

这篇关于如何使用Query Cursor跳转到特定页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆