gpt4 book ai didi

parse-platform - 将 Parse Object 传入云代码函数

转载 作者:行者123 更新时间:2023-12-01 00:47:11 28 4
gpt4 key购买 nike

我有一个创建 GueSTListInvite 的云代码功能

目的。它需要一个电话号码、一个访客列表对象和一个访客对象。

我像这样调用函数:

Parse.Cloud.run('createGuestlistInviteForExistingUser', {
phoneNumber: phoneNumber,
guestlist: guestlist,
guest: user
}).then(function(guestlistInvite) {
response.success(successfully created guestlistInvite');
});

客人名单和用户都是指针。但是在我的日志中,我收到一个错误:
Result: Error: Parse Objects not allowed here

知道为什么会这样吗?
Parse.Cloud.define('createGuestlistInviteForExistingUser', function(request, response) {

var phoneNumber = request.params.phoneNumber;
var guestlist = request.params.guestlist;
var guest = request.params.guest;

var guestlistInvite = new Parse.Object("GuestlistInvite");

guestlistInvite.save({
phoneNumber: phoneNumber,
Guestlist: guestlist,
Guest: guest,
checkInStatus: false,
response: 0
}).then(function(guestlistInvite) {
console.log('guestlistInvite for existing user was created');
response.success(guestlistInvite);
}, function(error) {
response.error('guestlistInvite was not saved');
});

});

最佳答案

您不能将整个 PFObject 作为请求参数发送来调用 Cloud Functions。

但是您可以简单地通过 实现该功能。将 PFObject 的 objectId 作为请求参数传递 然后在云代码中编写代码以从云代码中的objectId获取对象。

以下是使用 Promise 的云代码可能的样子:

Parse.Cloud.define("myFunction", functoin(request, response)
{
var MyObject = Parse.Object.extend("MyObjectClass"); //You can put this at the top of your cloud code file so you don't have to do it in every function
var myObject = new MyObject();
var myObjectId = request.params.myObjectId;

myObject.id = myObjectId;
myObject.fetch().then
(
function( myObject )
{
//do stuff with it
},
function( error )
{
response.error("There was an error trying to fetch MyObjectClass with objectId " + myObjectId + ": " + error.message);
}
);
});

关于parse-platform - 将 Parse Object 传入云代码函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33559945/

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