“无法设置未定义的属性'成功'”Parse.com Cloud Code中的Promise错误

时间:2013-08-02 01:37:51

标签: javascript parse-platform promise

我正在尝试从“RewardCodes”类中检索用户的所有记录。它们的数量可以超过1000。我有两个函数,一个用于查找记录的计数,另一个用于检索它们。如果count大于1000,那么我迭代检索函数。我收到此错误:{“code”:141,“error”:“TypeError:无法在Object.t.Cloud.run(Parse.js:1:71298)上设置undefined \ n的属性'成功'\ n .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);
        });

    });

1 个答案:

答案 0 :(得分: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);
    });

});