代码之家  ›  专栏  ›  技术社区  ›  Scaraux

解析afterfind,添加到响应的对象是客户端中的指针

  •  0
  • Scaraux  · 技术社区  · 7 年前

    我在和一个 afterFind 带有parse的cloud函数,只需执行一个额外的查询,并在响应中设置一个额外的对象。我希望在客户机中完全检索这个相同的对象,但它实际上是一个指针或其他东西,因为我需要调用 fetchIfNeeded 在访问它的数据之前。

    Parse.Cloud.afterFind("PublicationImage", function(request, response) {
    
        ...
    
        votesQuery.equalTo("author", user)
        votesQuery.containedIn("target", publicationImagesIds);
        votesQuery.find()
          .then(function(votes) {
            votes.forEach(function(vote) {
              voteTarget = vote.get("target");
              for (var i = 0; i < publicationImages.length; i++) {
                if (publicationImages[i].id == voteTarget.id) {
                  publicationImages[i].set("userVote", vote); <-- Here I add an obj
                }
              }
            });
            response.success(publicationImages);
          })
    
        ...
    
    });
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Scaraux    7 年前

    我刚刚发现,出于某种原因,有一个问题迫使您在将对象返回到客户机之前将其转换为JSON或对其进行编码,否则它将被视为指针并被接收。

    解决办法是:

    publicationImages[i].set("userVote", Parse._encode(vote));
    

    阅读更多信息 Here

    推荐文章