gpt4 book ai didi

javascript - 为什么我的函数无法在 Parse Cloud Code 中运行?当我在 Angular 和 Express 中测试时它有效

转载 作者:行者123 更新时间:2023-12-03 10:24:10 24 4
gpt4 key购买 nike

为什么我的代码没有进展?我在 Angular 和 Express 中测试了它,代码进展仅受无法使用新数据编辑用户表的限制,因为主 key 是必要的。我哪里出错了?

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);
});;
})

最佳答案

让我们先修复一些编码错误,然后才能继续。

添加“;”在以下代码的末尾。

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

然后将req更改为request

 var Ids = req.params.data

 var Ids = request.params.data

关于javascript - 为什么我的函数无法在 Parse Cloud Code 中运行?当我在 Angular 和 Express 中测试时它有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29484049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com