将Parse Object传递给云代码函数

时间:2015-11-06 05:13:24

标签: parse-platform cloud-code

我有一个创建GuestlistInvite

的云代码功能

对象。它需要一个phoneNumber,一个guestlist对象和一个guest对象。

我这样调用函数:

Result: Error: Parse Objects not allowed here

guestlist和user都是指针。但是在我的日志中收到错误:

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');
  });

});

知道为什么会这样吗?

{{1}}

1 个答案:

答案 0 :(得分:4)

您无法将整个PFObject作为请求参数发送给云函数。

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

在这里,利用承诺来了解云代码的样子:

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);
        }
    );
});