解析云代码访问对象

时间:2015-04-01 01:49:28

标签: javascript object parse-platform cloud-code

在我的查询中,如何访问Parse类中的对象? 就像将对象awayTeam设置为等于newAwayTeam对象一样?

这样的东西
CloseGameTime.set("awayTeam", "the newAwayTeam object");

原始代码

    Parse.Cloud.job("CloseGameTime", function(request, response) {
 
  Parse.Cloud.useMasterKey();
  
  var query = new Parse.Query("Score");

  query.first({
    success: function(CloseGameTime) {

    var newAwayTeamVar = request.object.get("newAwayTeam");

      CloseGameTime.set("isGameTime", "NO");
      CloseGameTime.set("awayTeam", newAwayTeamVar);


      CloseGameTime.save(null, {
        success: function(CloseGameTime) {
          response.success("Successfully updated the server.");
        },
        error: function(CloseGameTime, error) {
          response.error("Could not save changes to the server.");
        }
      });
    },
    error: function(error) {
      response.error("Could not find object.");
    }
  });
});

2 个答案:

答案 0 :(得分:1)

不应该太难。我已经在我的解析云代码上做了类似的事情,所以请试一试:

var awayTeamObject = request.object.get("newAwayTeam");
CloseGameTime.set("awayTeam", awayTeamObject);

答案 1 :(得分:0)

我发现你需要调用的只是成功的函数,后跟.get

var newAwayTeamVar = CloseGameTime.get("nextAwayTeam");

整个代码:

Parse.Cloud.job("CloseGameTime", function(request, response) {
 
  Parse.Cloud.useMasterKey();
  
  var query = new Parse.Query("Score");

  query.first({
    success: function(CloseGameTime) {

     var newAwayTeamVar = CloseGameTime.get("nextAwayTeam");


      CloseGameTime.set("isGameTime", "NO");
      CloseGameTime.set("awayTeam", newAwayTeamVar);
      CloseGameTime.set("nextAwayTeam", "");


      CloseGameTime.save(null, {
        success: function(CloseGameTime) {
          response.success("Successfully updated the server.");
        },
        error: function(CloseGameTime, error) {
          response.error("Could not save changes to the server.");
        }
      });
    },
    error: function(error) {
      response.error("Could not find object.");
    }
  });
});