简体   繁体   English

为什么我的函数在Parse Cloud Code中不起作用? 当我在Angular和Express中测试时它可以工作

[英]Why isn't my function working in Parse Cloud Code? It works when I test in Angular and Express

Why is my code not progressing? 为什么我的代码没有进展? I tested it in both Angular and Express and the code progressed limited only by the inability to edit the User table with new data because the Master Key is necessary. 我在Angular和Express中都对其进行了测试,并且代码的进展仅受无法使用新数据编辑User表的限制,因为必须使用主密钥。 Where am I going wrong? 我要去哪里错了?

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

Parse.Cloud.useMasterKey();

var user = Parse.Object.extend("User");
var query = new Parse.Query(Parse.User);
var Table1 = Parse.Object.extend("Table1");
var table1Query = new Parse.Query(Table1);
var Table2 = Parse.Object.extend("Table2");
var table2Query = new Parse.Query(Table2);

var Ids = request.params.data; //this is an array of Parse.Object Ids

var array = [];

var x = Ids.length;

while (x--){
var Id = Ids[x];
console.log("This is active");//I know this working
table1Query.equalTo("user", {__type: "Pointer", className: "_User",                                                                              
                             objectId: Id});
table1Query.find({
success: function (results) {
         var resultIds = _.map(results, function (n) {
                           return n.id});

         var resultObjs = _.map(results, function (n) {
                           return return _.extend(_.find(n), {id: n.id})});

var a = resultIds.length;
while (a--) {
var resultId = resultIds[a];
console.log("I don't know why this is not coming up!?!");//Why isn't this working?
table2Query.equalTo("user", {__type: "Pointer", className: "_User",                                                                              
                             objectId: resultId});
table2Query.find({
success: function (items) {
var MA = _.map(_.flatten(items), function (n) {
return _.find(n)});

var step3 = _.map(resultObjs, function (n) {return _.extend(n, {
Matched: _.filter(MA, function (a) {return a.result.id == n.id})})});

var total = Math.round(_.reduce(_.map(step3, function (n) {return n.Bill
}), function (memo, num) {return memo + num;}, 0) * 100) / 100;

var duty = function (total, id) {
var promise = new Parse.Promise();
table2Query.get(id, {
success: function (Answer) {
Answer.set("duty", total);
Answer.save().then(function (difresult) {
response.success(difresult);
}, function (error) {
response.error(error);})
}
});
}
    array.push(duty(Answer, Id));
    }
})
}
}
})
}
return 

Parse.Promise.when(array).then(function() {
    response.success("Successfully retrieved Total Bills.");
},
    function(error) {
        response.error("Something is still wrong");
        console.log(error);
    });;
    })

Let's fix some coding errors first before I can continue. 让我们先修复一些编码错误,然后再继续。

Add ';' 添加“;” at the end of the below code. 在以下代码的末尾。

 var Ids = req.params.data
 var x = Ids.length
 var a = resultIds.length
 array.push(duty(Answer, Id))

Then change req to request 然后换REQ 请求

 var Ids = req.params.data

to

 var Ids = request.params.data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM