I am attempting to save the username and userId from the User class when a user registers into another class, but for some reason the afterSave handler won't save any information. The code I am using currently is:
当用户注册到另一个类时,我试图从User类保存用户名和userId,但由于某种原因,afterSave处理程序不会保存任何信息。我目前使用的代码是:
Parse.Cloud.afterSave(Parse.User, function(request, response) {
// Check if the User is newly created
if (!request.object.existed()) {
// Set default values
var RunnerClass = Parse.Object.extend("Runner");
var runner = new RunnerClass;
runner.set("username", request.object.get("username"));
runner.set("userId", request.object.id);
runner.save(null, {
success: function(runner) {
response.success(runner);
},
error: function(error) {
response.error(error);
}
});
}
});
2 个解决方案
#1
0
Replace the below line
替换以下行
var runner = new RunnerClass;
with
var runner = new RunnerClass();
Also response.success() in the last line should be removed if you're expecting the returned response with runner object.
如果您期望使用runner对象返回响应,则应删除最后一行中的response.success()。
#2
0
You shouldn't call response.success()
at the end of the function.
您不应该在函数末尾调用response.success()。
The CloudCode guide says:
CloudCode指南说:
In general, you should wait for all network requests to finish before calling
success
通常,您应该在调用成功之前等待所有网络请求完成
The runner.save
function is asynchronous, so the call at the end of the function is getting called before it's execution terminates, and the Parse Cloud Runtime kills the save request.
runner.save函数是异步的,因此函数末尾的调用在执行终止之前被调用,而Parse Cloud Runtime会终止保存请求。
#1
0
Replace the below line
替换以下行
var runner = new RunnerClass;
with
var runner = new RunnerClass();
Also response.success() in the last line should be removed if you're expecting the returned response with runner object.
如果您期望使用runner对象返回响应,则应删除最后一行中的response.success()。
#2
0
You shouldn't call response.success()
at the end of the function.
您不应该在函数末尾调用response.success()。
The CloudCode guide says:
CloudCode指南说:
In general, you should wait for all network requests to finish before calling
success
通常,您应该在调用成功之前等待所有网络请求完成
The runner.save
function is asynchronous, so the call at the end of the function is getting called before it's execution terminates, and the Parse Cloud Runtime kills the save request.
runner.save函数是异步的,因此函数末尾的调用在执行终止之前被调用,而Parse Cloud Runtime会终止保存请求。