Parse Cloud Code Error: Parse.Error {code: 141, message: "success/error was not called"}
Parse Cloud Code Error: Parse.Error {code: 141, message: "success/error was not called"}
我想使用云代码有条件地更新几个 Parse.Objects。该函数应该将 select 数据保存到一个新列,如果它适用于有问题的用户。
我在第一个 Cloud Code 函数中遇到了一些严重的问题。我认为我的大部分内容都是正确的,但我一直收到 success/error was not called 错误。
我正在使用以下代码:
Parse.Cloud.define("someFunction", function(request, response) {
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 = req.body //this is an array of Parse.Object Ids
var array = [];
var x = Ids.length
while (x--){
var Id = Ids[x];
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];
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);
})
我希望有一天这对某人有所帮助。代码中的 answer/difference 可以在最后找到,因为我添加了 .then 来放置响应。success/error:
Parse.Cloud.define("someFunction", function(request, response) {
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 = req.body //this is an array of Parse.Object Ids
var array = [];
var x = Ids.length
while (x--){
var Id = Ids[x];
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];
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);
});;
})
我想使用云代码有条件地更新几个 Parse.Objects。该函数应该将 select 数据保存到一个新列,如果它适用于有问题的用户。
我在第一个 Cloud Code 函数中遇到了一些严重的问题。我认为我的大部分内容都是正确的,但我一直收到 success/error was not called 错误。
我正在使用以下代码:
Parse.Cloud.define("someFunction", function(request, response) {
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 = req.body //this is an array of Parse.Object Ids
var array = [];
var x = Ids.length
while (x--){
var Id = Ids[x];
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];
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);
})
我希望有一天这对某人有所帮助。代码中的 answer/difference 可以在最后找到,因为我添加了 .then 来放置响应。success/error:
Parse.Cloud.define("someFunction", function(request, response) {
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 = req.body //this is an array of Parse.Object Ids
var array = [];
var x = Ids.length
while (x--){
var Id = Ids[x];
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];
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);
});;
})