解析后保存云函数返回成功结果,但不执行成功函数 [英] Parse aftersave cloud function returns a success result but doesn't execute success function

查看:262
本文介绍了解析后保存云函数返回成功结果,但不执行成功函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取我的Aftersave Cloud函数来递增另一个数据表中的值时遇到了麻烦.在这方面,Parse文档有点令人困惑.

I'm having trouble getting my aftersave cloud function to increment a value in another data table. The Parse documentation is a bit confusing on this front.

我有一个名为"CandidateVotes"的表,该表为候选人"的每张选票存储一行-当保存新的选票行时,我想增加存储在名为"CategoryCandidates"的另一张表中的总选票数",每个候选人"都有一行.

I have a table called "CandidateVotes" that stores a row for each vote on a "candidate" - and when a new vote row is saved, I would like to increment the total votes count stored in a different table called "CategoryCandidates" which has a row for each "candidate".

所以相关信息:
-投票表称为候选人投票"
-候选人表称为"CategoryCandidates"
-CategoryCandidates表中的总投票计数"列被调用 投票"
-我要初始化"CategoryCandidates"行,其"votes"值为0

So the relevant information:
- Votes table is called "CandidateVotes"
- Candidates table is called "CategoryCandidates"
- Total votes count column in CategoryCandidates table is called "votes"
- I'm initializing the "CategoryCandidates" row with a "votes" value of 0

这是我的解析后保存云功能:

Here's my Parse aftersave cloud function:

Parse.Cloud.afterSave("CandidateVotes", function(request) {
  query = new Parse.Query("CategoryCandidates");
  query.get(request.object.get("candidateID").objectID, {
    success: function(candidate) {
      candidate.increment("votes");
      candidate.save();
    },
    error: function(error) {
    }
  });
});

这是我在云代码日志中看到的:

This is what I see in the cloud code log:

I2015-09-05T04:18:21.151Z]v15 after_save triggered for CandidateVotes for user 7YfU2ETvb3:
  Input: {"object":{"candidateID":{"__type":"Pointer","className":"CategoryCandidates","objectId":"XcfYPgijtn"},"createdAt":"2015-09-05T04:18:21.150Z","objectId":"sLySF6MvvQ","updatedAt":"2015-09-05T04:18:21.150Z","userID":{"__type":"Pointer","className":"_User","objectId":"7YfU2ETvb3"}}}
  Result: Success

但投票"列未增加.仍为0.

BUT the "votes" column is not incrementing. It remains 0.

任何想法都将不胜感激!

Any ideas would be very much appreciated!

推荐答案

objectId属性在JavaScript中只是id.

The objectId property is just id in JavaScript.

//replace
request.object.get("candidateID").objectID
//with this
request.object.get("candidateID").id

这篇关于解析后保存云函数返回成功结果,但不执行成功函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆