我使用parse.com作为我的后端。
我已经制作了下面的云代码,它给了我{u'code': 141, u'error': u'success/error was not called'}
代码。我知道我在第一次成功后没有进行response.success调用,但是我在名为nextSaleRate的链接函数中进行调用。
有没有办法解决这个问题?
以下是完整代码:
function SaleWithRate(){
saleId = undefined;
rating = 0.0;
}
function nextSaleRate(saleList, nextSale, arr, response){
if(nextSale < saleList.length) {
var sale = new SaleWithRate();
sale.saleId = saleList[nextSale].id;
//creating ShaleSale object for Rates query
var ShaleSale = Parse.Object.extend("ShaleSale");
var saleForRate = new ShaleSale();
saleForRate.id = sale.saleId;
//query
var rateQuery = new Parse.Query("ShaleSaleRate");
rateQuery.equalTo("saleId", saleForRate);
rateQuery.find({
success: function(rateList) {
var sum = 0;
var index = 0;
for(var j = 0; j < rateList.length; j++) {
index++;
sum += rateList[j].get("rate");
if(index === 0) {
sale.rating = 0;
}
else {
sale.rating = sum/index;
}
arr.push(sale);
nextSale++;
nextSaleRate(saleList, nextSale, arr, response);
}
},
error: function() {
response.error("rate lookup failed");
}
});
}
else {
console.log("when do I get in" + nextSale);
response.success(arr);
}
}
Parse.Cloud.define("getSalesWithRate", function(request, response){
var query = new Parse.Query("ShaleSale");
query.ascending("createdAt");
//query.notContainedIn("objectId", request.params.saleIds);
query.find({
success: function(results) {
var arr = new Array();
nextSaleRate(results, 0, arr, response);
},
error: function() {
response.error("sale lookup failed");
}
});
});
答案 0 :(得分:1)
错误消息实际上指的是没有从您的Cloud Function调用response.success()这一事实。您没有将响应对象传递给下一个“销售率”功能。