具有保存功能的Parse.Object的子类

时间:2013-03-13 07:51:54

标签: parsing

我将Parse.Object子类化如下:

    var CFSScoreData = Parse.Object.extend("CFSScoreData",
{
    initialize:function () {
        this.playerName = "RACCOON";
        this.playTimeInSec = 0;
        this.rank = 0;
            this.updateScore();
    },
    updateScore:function () {
        this.set("playerName", this.playerName);
        this.set("playTimeInSec", this.playTimeInSec);
        this.set("rank", this.rank);
    },
    saveScore:function () {
        this.updateScore();
        this.save(null, {
              success: function() {
                  alert("saveSuccess");
              },
              error: function(error) {
                  alert("saveError");
              }
        });
    },
}
);

这很好。

但是我希望在保存后获取对象的id,所以我尝试了:

saveScore:function () {
    this.updateScore();
    this.save(null, {
          success: function(this) {
              alert("saveSuccess" + this.id);
          },
          error: function(error) {
              alert("saveError");
          }
    });
},

但它没有用......

任何建议都会表示赞赏,谢谢:)

1 个答案:

答案 0 :(得分:0)

我很傻〜

应该是:

saveScore:function () {
    this.updateScore();
    this.save(null, {
          success: function(scoreData) {
              alert("saveSuccess" + scoreData.id);
          },
          error: function(error) {
              alert("saveError");
          }
    });
},