Parse.com Cloud Code - 在SaveAll响应中返回ParseObject

时间:2015-01-28 15:39:58

标签: javascript parse-platform cloud-code

query.get(playerID, {
  success: function(player) {

      var numOfCoins = activeTeam.get("numOfCoins");
      var playerPrice = player.get("price");

      // Check if they have enough coins
      if(numOfCoins >= playerPrice)
      {                                       
         // Add to buy player array
         var NewTeam = Parse.Object.extend("NewTeam");
         var passiveTeam = new NewTeam();
         passiveTeam.id = player.get("team").id;

         // Remove from passive team (seller) array
         passiveTeam.remove("players", player);

         // Set player's team to the buyer's team (active team)
         player.set("team", activeTeam);

         // Add to the active team (buyer) array
         activeTeam.add("players", player);

         // ------ Save the player and both teams ------
         Parse.Object.saveAll([activeTeam, passiveTeam, player], {
            success: function(list)
            {
              response.success(list[2]); // also tried response.success(player);
            },
            error: function(error)
            {
              response.error(error);
            }
        });

我发布了一个代码块(上图),用于查询播放器(基于客户端请求的ID)获取Player对象并保存。如果SaveAll成功,我想将修改后的播放器返回给客户端。

但是,我收到以下错误“失败:未捕获尝试使用指向未保存新对象的指针保存对象。”

我已经尝试在列表中使用索引来返回响应中的ParseObject并使用变量名。

保存后是否需要再次查询播放器并在响应中返回?似乎有点矫枉过正需要另一个API请求来查询我刚修改并保存的播放器。

非常感谢任何帮助。谢谢Alex。

0 个答案:

没有答案