gpt4 book ai didi

javascript - 将 afterSave 与 Parse Cloud Code 结合使用

转载 作者:行者123 更新时间:2023-11-28 07:04:13 25 4
gpt4 key购买 nike

我在学习 Cloud Code 的第 3 天,取得的进展微乎其微。我对调用过程的工作方式感到困惑。在 Cloud Code 中,我需要使用 afterSave 来查询一个类,其中键“sent”等于 false,并且对于收件人数组中的每个收件人,向每个收件人推送通知并将“sent”设置为 true。

我在 main.js 中保存了 afterSave 函数,但每次我使用 PFCloud.callFunctionInBackground() 调用它时,我都会收到 [Error]: function not found(代码: 141,版本:1.7.2)

这是我的 afterSave 触发器:

Parse.Cloud.afterSave("Send", function(request) {
query = new Parse.Query("Shares");
query.get(request.object.get("share").id, {
success: function(post) {
console.success("Howdy");
},
error: function(error) {
console.error("Got an error " + error.code + " : " + error.message);
}
});
});

我在这里调用 Swift 中的函数:

PFCloud.callFunctionInBackground("Send", withParameters: nil) {
(response: AnyObject?, error: NSError?) -> Void in
let result = response as? String
println(result)

}

如果我在 saveInBackgroundWithBlock 闭包中调用 afterSave 触发器,我是否使用 PFCloud.callFunctionInBackground 调用它?

最佳答案

我认为 afterSave 正在做一些与您想象的不同的事情 - 它会在您保存对象时自动触发。在这种情况下,如果您有一个 Send 类型的对象,并且您更新并保存了该对象,您的 afterSave 函数将被调用。例如,这对于验证保存的对象是否有效或更新相关对象通常很有用。

我觉得你可以用 Cloud Function 完成你想做的事情.您可以从 Swift 代码中调用它,它是一个独特的命名函数,而不是一个自动调用的函数。

关于javascript - 将 afterSave 与 Parse Cloud Code 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31215464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com