我不熟悉 Javascript 或 Cloud Code,昨天才开始使用 CC。这似乎是一项极其简单的任务,但我正在绞尽脑汁想弄明白。
保存“聊天”对象进行解析时,我想增加“聊天室”对象的“numberOfMessages”(数字类型)字段,其中 ChatRooms.objectId = Chat.RoomId
简单。我已经尝试了很多很多东西,这是直接来自 Parse Docs 的最新版本。
Parse.Cloud.beforeSave("Chat", function(request, response) {
query = new Parse.Query("ChatRooms");
query.get(request.object.get("roomId"), {
success: function(post) {
post.increment("numberOfMessages", 1);
post.save();
response.success();
},
error: function(error) {
console.error("Got an error " + error.code + " : " + error.message);
response.error();
}
});
});
在这个例子中,错误是:
ReferenceError: response is not defined
at query.get.success (main.js:7:33)
at Parse.js:2:7706
at e (Parse.js:2:6486)
at Parse.js:2:5935
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:664)
at c.extend.resolve (Parse.js:2:5886)
at e (Parse.js:2:6621)
at Parse.js:2:5935
at Array.forEach (native) (Code: 141, Version: 1.5.0)
感谢任何指点。
最后.. 是否有任何学习 Javascript 的好资源,因为它与 Parse Cloud Code 相关?我的搜索没有找到任何有用的东西。谢谢!
最佳答案
替换
request.object.get("roomId").id
与
request.object.get("roomId")
因为 roomId
是一个字符串而不是 Room 对象。
更新:此外,将 response.success()
添加到成功处理程序并将 response.error()
添加到错误处理程序以让Parse.com 知道你已经完成了。
关于javascript - 解析云代码增量问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27386535/