如何使用 Javascript SDK 调用带有参数的云代码函数
How do I call a cloud code function with parameters using the Javascript SDK
我知道在 iOS sdk 中我可以这样做
[PFCloud callFunctionInBackground:@"email" withParameters:@{@"param1": @"quantity1, @"param2": @"quantity2} block:^(NSString *result, NSError *error) {
if (error) {
//error
} else {
// make sure the set the email sent flag on the object
NSLog(@"result :%@", result);
}
}];
但是我如何使用 Javascript 函数来做到这一点
Parse.Cloud
实施 run()
...
Parse.Cloud.run("email", { param1:"quantity1", param2:"quantity2" }).then(function(result) {
// make sure the set the email sent flag on the object
console.log("result :" + JSON.stringify(result))
}, function(error) {
// error
});
Parse.Cloud.define("email", function(request, response) {
var param1 = request.params.param1;
var param2 = request.params.param2;
response.success("success"); //your response
}, function(error) {
// Make sure to catch any errors, otherwise you may see a "success/error not called" error in Cloud Code.
response.error("Could not retrieve Posts, error " + error.code + ": " + error.message);
});
使用以下代码完美工作
NSDictionary *param = [[NSDictionary alloc] initWithObjectsAndKeys:@"A",@"param1",@"B",@"param2", nil];
[PFCloud callFunctionInBackground:@"email" withParameters:param block:^(id object, NSError *error)
{
}];
我知道在 iOS sdk 中我可以这样做
[PFCloud callFunctionInBackground:@"email" withParameters:@{@"param1": @"quantity1, @"param2": @"quantity2} block:^(NSString *result, NSError *error) {
if (error) {
//error
} else {
// make sure the set the email sent flag on the object
NSLog(@"result :%@", result);
}
}];
但是我如何使用 Javascript 函数来做到这一点
Parse.Cloud
实施 run()
...
Parse.Cloud.run("email", { param1:"quantity1", param2:"quantity2" }).then(function(result) {
// make sure the set the email sent flag on the object
console.log("result :" + JSON.stringify(result))
}, function(error) {
// error
});
Parse.Cloud.define("email", function(request, response) {
var param1 = request.params.param1;
var param2 = request.params.param2;
response.success("success"); //your response
}, function(error) {
// Make sure to catch any errors, otherwise you may see a "success/error not called" error in Cloud Code.
response.error("Could not retrieve Posts, error " + error.code + ": " + error.message);
});
使用以下代码完美工作
NSDictionary *param = [[NSDictionary alloc] initWithObjectsAndKeys:@"A",@"param1",@"B",@"param2", nil];
[PFCloud callFunctionInBackground:@"email" withParameters:param block:^(id object, NSError *error)
{
}];