【问题标题】:PFQuery Only Returning 100PFQuery 只返回 100
【发布时间】:2018-02-13 16:45:46
【问题描述】:

我认为 PFQuery 应该有 1000 个限制,但我遇到了一个问题,它使用以下代码只返回 100 个对象:

- (id)initWithCoder:(NSCoder *)aDecoder
{
    NSLog(@"initwithcoder");
    self = [super initWithCoder:aDecoder];
    if (self) {
        NSLog(@"self");
        // The className to query on
        self.parseClassName = @"Directory";

        // Whether the built-in pull-to-refresh is enabled
        self.pullToRefreshEnabled = YES;

        // Whether the built-in pagination is enabled
        self.paginationEnabled = NO;

        // The number of objects to show per page
        self.objectsPerPage = 0;


    }
    return self;
}
- (PFQuery *)queryForTable {
    NSLog(@"QUERY");
    PFQuery *query = [PFQuery queryWithClassName:@"Directory"];
    // If no objects are loaded in memory, we look to the cache first to fill the table
    // and then subsequently do a query against the network.
    if (self.objects.count == 0) {
        query.cachePolicy = kPFCachePolicyCacheThenNetwork;
    }
    NSLog(@"Count%lu", self.objects.count);
    [query orderByAscending:@"title"];

    return query;
}

我尝试过使用“0”以及“500”或“1000”,但没有任何变化。即使将其设置为 2 的低计数仍然返回 100,所以就好像我的应用程序完全忽略了那行代码。

【问题讨论】:

  • 把这段代码放在initWithCoder之外

标签: ios parse-platform pfquery


【解决方案1】:

limit 默认为 100。

http://parseplatform.org/Parse-SDK-iOS-OSX/api/Classes/PFQuery.html#/Paginating%20Results

要返回的对象数量的限制。 默认限制为 100,一次返回最多 1000 个结果。

所以只需调用:

query.limit = xxx

这是在 Parse Server v2.1.0 中添加的:

修复:现在进行无限制的查询会返回 100 个结果 参考:https://github.com/parse-community/parse-server/blob/master/CHANGELOG.md#210-2172016

源码:https://github.com/parse-community/parse-server/blob/master/src/Routers/ClassesRouter.js#L117


还有一个名为maxLimit的相关参数,它是服务器范围的,代表Max value for limit option on queries, defaults to unlimited

【讨论】:

  • 谢谢...在添加之前我就没有使用过它。
猜你喜欢
  • 1970-01-01
  • 2017-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-15
相关资源
最近更新 更多