簡體   English   中英

iOS App Engine端點分頁

[英]ios app engine endpoints paging

我正在嘗試找出如何在分頁中使用Google Cloud Endpoints。 我只得到10個結果。 我已經將屬性shouldFetchNextItems設置為YES。 另外,我的查詢對象沒有nextToken或maxResults屬性。 有一個帶有pageToken的GTLQueryCollectionProtocol,但我看不到它的使用位置。

static GTLServiceOwnit *service = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    service = [[GTLServiceOwnit alloc] init];
    service.retryEnabled = YES;
    service.shouldFetchNextPages = YES;
});

NSError *error;

NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];

GTLQueryOwnit *query = [GTLQueryOwnit queryForBrandList];

[service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLOwnitBrandCollection *object, NSError *clouderror) {
   NSLog(@"counts: %d", [[object items] count]);
   ...

編輯:這是我在python中的后端:

class Brand(EndpointsModel):
    name = ndb.StringProperty(required=True)

@Brand.query_method(path='brand',
                    http_method='GET',
                    name='brand.list')
def brand_list(self, query):
    """Exposes an API endpoint to query for brands for the current user"""
    return query.order(Brand.name)

謝謝,

從文檔中檢查分頁樣本。

為了將分頁參數包含在您的API中,您需要在方法中明確包含它們:

@Brand.query_method(query_fields=('limit', 'pageToken'),
                    path='brand',
                    http_method='GET',
                    name='brand.list')
def brand_list(self, query):
    """Exposes an API endpoint to query for brands for the current user"""
    return query.order(Brand.name)

查詢限制的默認值為10 您可以更改它,但應該設置一個合理的limit 這是limit_default現場query_method

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM