无法将 iOS 中的多个参数发送到 Cloud Code
Can not Sending multiple parameters from iOS to Cloud Code
没有发生错误,但是当我 运行 编程时它崩溃了。
应用代码
@property (nonatomic, strong) NSDate *CurrentDate;
- (void) GetCalUsed{
NSMutableDictionary *params = [NSMutableDictionary new];
PFUser *user = [PFUser currentUser];
CurrentDate = [NSDate date];
params[@"user"] = user.objectId;
params[@"date"] = CurrentDate;
[PFCloud callFunctionInBackground:@"CalUsed"
withParameters:params
block:^(NSNumber *CalUsed1, NSError *error) {
if (!error) {
NSLog(@"Calories : %@",CalUsed1);
CalUsed = CalUsed1;
NSLog(@"Selected Date : %@",CurrentDate);
}
}];
}
云码
Parse.Cloud.define("CalUsed", function(request, response) {
var user = request.user;
var date = request.date;
var query = new Parse.Query("FoodLog");
query.equalTo("user",user);
query.equalTo("Date",date);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("Calories");
}
response.success(sum);
},
error: function() {
response.error("lookup failed");
}
});
});
我试过按照这个方法sending multiple parameters in "withParameters:" call但是没用。
您应该 .params
在请求之后和字典键之前:
Parse.Cloud.define("CalUsed", function(request, response) {
var user = request.params.user;
var date = request.params.date;
var query = new Parse.Query("FoodLog");
query.equalTo("user",user);
query.equalTo("Date",date);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("Calories");
}
response.success(sum);
},
error: function() {
response.error("lookup failed");
}
});
});
没有发生错误,但是当我 运行 编程时它崩溃了。
应用代码
@property (nonatomic, strong) NSDate *CurrentDate;
- (void) GetCalUsed{
NSMutableDictionary *params = [NSMutableDictionary new];
PFUser *user = [PFUser currentUser];
CurrentDate = [NSDate date];
params[@"user"] = user.objectId;
params[@"date"] = CurrentDate;
[PFCloud callFunctionInBackground:@"CalUsed"
withParameters:params
block:^(NSNumber *CalUsed1, NSError *error) {
if (!error) {
NSLog(@"Calories : %@",CalUsed1);
CalUsed = CalUsed1;
NSLog(@"Selected Date : %@",CurrentDate);
}
}];
}
云码
Parse.Cloud.define("CalUsed", function(request, response) {
var user = request.user;
var date = request.date;
var query = new Parse.Query("FoodLog");
query.equalTo("user",user);
query.equalTo("Date",date);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("Calories");
}
response.success(sum);
},
error: function() {
response.error("lookup failed");
}
});
});
我试过按照这个方法sending multiple parameters in "withParameters:" call但是没用。
您应该 .params
在请求之后和字典键之前:
Parse.Cloud.define("CalUsed", function(request, response) {
var user = request.params.user;
var date = request.params.date;
var query = new Parse.Query("FoodLog");
query.equalTo("user",user);
query.equalTo("Date",date);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("Calories");
}
response.success(sum);
},
error: function() {
response.error("lookup failed");
}
});
});