2013-05-13 56 views
4

我遇到此错误,这是我的云代码。失败:Uncaught尝试使用指向新的未保存对象的指针保存对象

var HighScore = Parse.Object.extend("HighScore"); 
highScore = new HighScore(); 
highScore.set("totalXp", request.params.totalXp); 
highScore.set("regionId", request.params.regionId); 

var relation = highScore.relation("userId"); 
relation.add(request.user); 

highScore.save(); 

response.success(highScore); 

响应返回为空,但奇怪的是,当我查看数据浏览器时,关系成功添加。

找不到确切的答案或解释。请帮忙。

回答

4

我提到here,并修改我的代码。原因是因为我在1 save()操作中创建了对象并添加了关系。

var HighScore = Parse.Object.extend("HighScore"); 
highScore = new HighScore(); 
highScore.set("totalXp", request.params.totalXp); 
highScore.set("regionId", request.params.regionId); 

highScore.save(null, { 
    success: function(savedHighScore){ 
      var relation = savedHighScore.relation("userId"); 
      relation.add(request.user); 
      //relation.add(Parse.User.current()); 
     savedHighScore.save(null, { 
      success: function(finalHighScore){ 
       response.success(finalHighScore); 
      }, 
      error: function(finalHighScore, error){ 
      } 
     }); 
    }, 
    error: function(highScore, error){ 
     console.log("failed to create"); 
    } 
});