我尝试从Parse CloudCode函数中更新Parse对象。我想更新一个特定条目的status_id,它的objectId是“vZveFx3KcP”。每当我调用以下函数时,没有更新任何条目。但是每当我从Android设备中添加手动条目或条目时,它就会被更新。对于iOS,我使用的是最新的分析版本"1.11.0“。只对由iOS平台添加的条目进行了更新。。
有谁能解释一下我哪里出错了吗?我是javascript编程新手,所以如果您需要我提供更多的信息,请告诉我。你可以在下面检查我的代码。我尝试过从Parse控制台调用云函数。
Parse.Cloud.define("freshFunction", function(request, response) {
var GameScore = Parse.Object.extend("Booking");
var query = new Parse.Query(GameScore);
query.equalTo("objectId", "vZveFx3KcP");
query.first({
success: function(results) {
alert("Successfully retrieved " + results.length + "user_id");
results.set("status_id", 2);
results.save();
response.success();
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
response.error();
}
});
});发布于 2016-01-07 12:36:52
通过创建云函数并从iOS平台调用它,解决了这个问题。在云中添加了以下代码。
Parse.Cloud.define("callCloudFunctionFromDevice", function(request, response) {
var bookfromtime = request.params.book_fromtime;
var booktotime = request.params.book_totime;
var bookdate = request.params.book_date;
var roommacid = request.params.room_mac_id;
var userid= request.params.user_id;
var ttl= request.params.title;
var desc= request.params.description;
var statusid= request.params.status_id;
var SensorsObject = Parse.Object.extend("Booking");
var senorObject = new SensorsObject();
senorObject.set("book_fromtime", bookfromtime);
senorObject.set("book_totime", booktotime);
senorObject.set("book_date", bookdate);
senorObject.set("room_mac_id", roommacid);
senorObject.set("user_id", userid);
senorObject.set("title", ttl);
senorObject.set("description", desc);
senorObject.set("status_id", statusid);
senorObject.save(null, {
success: function(gameScore) {
// response.success("Sensor Data is stored");
response.success("success");
},
error: function(gameScore, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
alert('Failed to create new object, with error code: ' + error.message);
response.error("Failed to store object data");
}
});
});一旦在云中部署了上面的代码,我就从iOS平台调用‘iOS’函数。请参阅以下代码
[PFCloud callFunctionInBackground:@"callCloudFunctionFromDevice" //This is the Parse function
withParameters:mDictionary
block:^(NSString *CalUsed1, NSError *error) { // This is where the block starts
if (!error) { //if the block retrieves the data with no problem, this will run
NSLog(@"Calories");
[self hideBusyActivityView];
[self.navigationController popViewControllerAnimated:YES];
}
else
{
NSLog(@"TDEE IN FN is");
[self hideBusyActivityView];
[self showAlertWithMessage:error.localizedDescription];
}
}];其中mDictionary是有效载荷。
谢谢,
阿克夏·艾赫。
https://stackoverflow.com/questions/34544262
复制相似问题