如何从Parse.com检索超过1000行?

Squ*_*ire 19 android listview parse-platform

我一直在使用Parse来检索列表视图的数据.不幸的是,他们默认将请求限制为100,最大为1000.在班上,我已经超过了1000.我在网上找到了一个链接,显示了在iOS上进行操作的方法,但是如何在Android上进行操作呢?网页链接

我目前正在循环中将所有数据添加到一个arraylist中,直到所有项目都完成(100)然后将它们添加到列表中

Squ*_*ire 43

我已经想出如何实现我的目标:

声明全局变量

private static List<ParseObject>allObjects = new ArrayList<ParseObject>();
Run Code Online (Sandbox Code Playgroud)

创建查询

final ParseQuery parseQuery = new ParseQuery("Objects");
parseQuery.setLimit(1000);
parseQuery.findInBackground(getAllObjects());
Run Code Online (Sandbox Code Playgroud)

回调查询

int skip=0;
FindCallback getAllObjects(){
    return new FindCallback(){
        public void done(List<ParseObject> objects, ParseException e) {
            if (e == null) {

                allObjects.addAll(objects);
                 int limit =1000;
                if (objects.size() == limit){
                    skip = skip + limit;
                    ParseQuery query = new ParseQuery("Objects");
                    query.setSkip(skip);
                    query.setLimit(limit);
                    query.findInBackground(getAllObjects());
                }
                //We have a full PokeDex
                else {
                    //USE FULL DATA AS INTENDED
                }
        }
    };
}
Run Code Online (Sandbox Code Playgroud)


小智 14

这是一个没有承诺的JavaScript版本..

这些是全局变量(集合不是必需的,只是我的坏习惯)..

   ///create a collection of cool things and instantiate it (globally)
    var CoolCollection = Parse.Collection.extend({
       model: CoolThing
    }), coolCollection = new CoolCollection();
Run Code Online (Sandbox Code Playgroud)

这是获取结果的"循环"功能..

//recursive call, initial loopCount is 0 (we haven't looped yet)
function getAllRecords(loopCount){

    ///set your record limit
    var limit = 1000;

    ///create your eggstra-special query
     new Parse.Query(CoolThings)
            .limit(limit)
            .skip(limit * loopCount) //<-important
            .find({
             success: function (results) {
                 if(results.length > 0){

                     //we do stuff in here like "add items to a collection of cool things"
                     for(var j=0; j < results.length; j++){
                         coolCollection.add(results[j]);
                     }

                     loopCount++; //<--increment our loop because we are not done

                     getAllRecords(loopCount); //<--recurse
                 }
                 else
                 {
                     //our query has run out of steam, this else{} will be called one time only
                     coolCollection.each(function(coolThing){
                        //do something awesome with each of your cool things
                     });
                 }
            },
             error: function (error) {
                //badness with the find
             }
         });
}
Run Code Online (Sandbox Code Playgroud)

这就是你如何称呼它(或者你可以通过其他方式实现):

getAllRecords(0);
Run Code Online (Sandbox Code Playgroud)