4

我有这个错误,这是我的云代码。

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

1 回答 1

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");
    }
});
于 2013-05-13T03:42:37.637 回答