解析云代码查询未执行

解析云代码查询未执行,第1张

我有以下云代码功能,当我从OS X应用程序调用此功能时,我也获得了成功响应。但是,查询操作的成功和失败块内的控制台日志输出消息都不会被执行。关于在哪里看的任何想法都将非常感激。

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

  Parse.Cloud.useMasterKey();
  var Alert = Parse.Object.extend("Alert");
  var query = new Parse.Query(Alert);
  query.get("vC6ppoxuqd", {
    success: function(alertObj) {
      // The object was retrieved successfully.
      var status = alertObj.get("status");
      console.log("RECEIVED OBJECT WITH STATUS:");
      console.log(status);
      if (status == "active") {
        console.log("active");
        markActiveAlertAsExpired(alertObj);
      } else if (status == "inactive") {
        console.log("inactive");
        markInactiveAlertAsExpired(alertObj);
      } else {
        console.error("unknown_status");
      }
    },
    error: function(object, error) {
      // The object was not retrieved successfully.
      // error is a Parse.Error with an error code and message.
      console.error("alert_not_found");
      response.error("alert_not_found");
    }
  });

  response.success("available");
});

最佳答案:

1 个答案:

答案 0 :(得分:1)

在调用response.success之前,您需要等待查询完成,下面的更新代码才有效。

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

  Parse.Cloud.useMasterKey();
  var Alert = Parse.Object.extend("Alert");
  var query = new Parse.Query(Alert);
  query.get("vC6ppoxuqd", {
    success: function(alertObj) {
      // The object was retrieved successfully.
      var status = alertObj.get("status");
      console.log("RECEIVED OBJECT WITH STATUS:");
      console.log(status);
      if (status == "active") {
        console.log("active");
        markActiveAlertAsExpired(alertObj);
      } else if (status == "inactive") {
        console.log("inactive");
        markInactiveAlertAsExpired(alertObj);
      } else {
        console.error("unknown_status");
      }
      response.success("available");
    },
    error: function(object, error) {
      // The object was not retrieved successfully.
      // error is a Parse.Error with an error code and message.
      console.error("alert_not_found");
      response.error("alert_not_found");
    }
  });


});
本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复