1

我正在尝试从“RewardCodes”类中检索用户的所有记录。它们的数量可能超过 1000 个。我有 2 个函数,一个用于查找记录的计数,另一个用于检索它们。如果计数大于 1000,那么我迭代检索函数。我收到此错误: {"code":141,"error":"TypeError: Cannot set property 'success' of undefined\n at Object.t.Cloud.run (Parse.js:1:71298)\n at main .js:1715:14"} 这里是代码:

Parse.Cloud.define("countInteractions", function (request, response){
    var myUser = new Parse.Object("_User");
    myUser.id = request.params.userId;
    var query = new Parse.Query("RewardCodes");
    query.equalTo("UserID",myUser);
    query.count({
        success: function(count){
                var number = 0;
                var Interactions =0;
                number = count;
                interactions = ~~(number / 1000) + 1;
                response.success(interactions); 
            },
            error: function(error){
                response.error(error);
            }
        });
    });



    Parse.Cloud.define("getWonRecords", function (request, response){

        var myId = request.params.objectId;
        var list = [];
        var myUser = new Parse.Object("_User");
        myUser.id = request.params.userId;
        var query = new Parse.Query("RewardCodes");
        query.limit(1000);
        query.equalTo("UserID",myUser);
    //  query.exists("Code");
        query.equalTo("Used",true);
        query.ascending("objectId");
        query.greaterThan("objectId",myId); 
        query.include("CampaignID");
        query.include("UserID");
        query.find({
            success: function(results){
                for(var i=0; i<results.length; i++){
                    var myObject = {
                                    SERIAL:     i,
                                    RCodesId:   results[i].id,
                                    brand:      results[i].get("CampaignID").get("brandId"),
                                    campaignId: results[i].get("CampaignID").id,
                                    code:       results[i].get("Code"),
                                    topText:    results[i].get("CampaignID").get("KazanTextTop"),
                                    bottomText: results[i].get("CampaignID").get("KazanTextBottom")
                                    };
                    list.push(myObject);
                }
                response.success(list); 

            },
            error: function(error){
                response.error(error);
            }
        });
    });


    Parse.Cloud.define("wonRewards3", function (request, response){

        var mainList = [];

    /*ERROR here*/
    Parse.Cloud.run("countInteractions",{userId: request.params.userId}).then(function(Interactions){
            for(var i=0;i<Interactions; i++){
                Parse.Cloud.run("getWonRecords",{objectId: myId, userId: request.params.userId}).then
                (function(list){
                    myId = list[list.length - 1].RCodesId;
                    mainList.push(list);    
                });
            }
            return mainList;
        }).then(function(results){
            response.success(results);
            }, function(error){
                response.error(error);
        });

    });
4

1 回答 1

0

哇,这里好乱

    Parse.Cloud.define("wonRewards3", function (request, response){

    var mainList = [];
    // you forgot your });
    /*ERROR here*/
Parse.Cloud.run("countInteractions",{userId: request.params.userId}).then(function(Interactions){
        for(var i=0;i<Interactions; i++){
            Parse.Cloud.run("getWonRecords",{objectId: myId, userId: request.params.userId}).then
            (function(list){
                myId = list[list.length - 1].RCodesId;
                mainList.push(list);    
            });
        }
        return mainList;
    }).then(function(results){
        response.success(results);
        }, function(error){
            response.error(error);
    });

});
于 2014-02-06T14:48:19.300 回答