如何使用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)
{
}];
相关文章:
- 带有键代码参数Jquery的模拟按键功能
- 代码气味-将布尔控制参数传递给函数
- 了解插件代码中$.each内部传递的参数的用法
- 如何通过 javascript 访问参数化函数背后的代码
- 在Javascript代码中插入URL参数
- 读取URL参数时,代码未获得预期值
- 传递参数的问题,以及为MYSQL集成准备代码的问题
- 使用继承配置netzkejavascript代码(在带有参数的父类中定义js代码)
- 如何通过 URL 将参数传递给 GAE 上的 JavaScript 代码
- JQuery:将参数传递给插件以限制代码执行
- 如何正确传递 Parse.com 云代码参数
- 尝试制作可重用的代码,使用函数参数填充名为 target 的变量的区域
- 如何在谷歌跟踪代码管理器 noscript 标签中参数化容器 id
- 在 Ember 视图参数更改上运行代码
- 如何为此 jquery 代码使用函数参数,或者是否有更好的解决方案
- 如何在 asp.net 中使用 C# 代码将参数传递给 JavaScript 函数
- 将重复出现的代码“外包”到带有参数(js)的函数中
- 如何将两个函数的代码与不同的参数组合在一起
- 将javascript函数的参数传递给java代码
- 加载json-url参数代码(javascript修改)