0

我使用 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");
    }
  });
});
4

1 回答 1

1

错误消息实际上是指没有从您的云函数调用 response.success() 的事实。您没有将响应对象传递给下一个销售率函数。

于 2013-06-02T01:41:25.963 回答