语境
我在Web 应用程序的后端之后使用Parse.com 。我遇到的问题与Cloud Code有关。
在用户完成他们的个人资料后,我想调用一个afterSave()函数来更新数据集 MY_TABLE 中的一些字段。
正在更新的字段(variable01、variable02 和 variable03)是通过函数 MY_FUNCTION 检索的,输入 param01 和 param02。
错误
我收到以下错误,我无法修复:“未捕获尝试使用指向新的未保存对象的指针保存对象。”
代码
Parse.Cloud.afterSave("PROFILE_COMPLETE", function(request) {
// Use Master Key
Parse.Cloud.useMasterKey();
// Identify Parameters in Request
var param01 = request.user.get('param01');
var param02 = request.user.get('param02');
// Print Parameters to Console
console.log("Parameter 01 (" + param01 + ") successfully identified");
console.log("Parameter 02 (" + param02 + ") successfully identified");
// Identify Variables by Calling MY_FUNCTION()
Parse.Cloud.run('MY_FUNCTION', {param01: param01, param02: param02}, {
success: function(results) {
// Print Results
console.log("Function MY_FUNCTION() returned successful response");
console.log(results);
// Print Result Variables
console.log("Identified variable01 = " + results.variable01);
console.log("Identified variable02 = " + results.variable02);
console.log("Identified variable03 = " + results.variable03);
// Do I need to extend MY_TABLE or something else here???
// I am doing the update and save wrong...
// Update 'Complete' Data
request.object.set("variable01", results.variable01);
request.object.set("variable02", results.variable02);
request.object.set("variable03", results.variable03);
// Save Variables to 'MY_TABLE'
request.object.save(null, {
success: function(results) {
console.log("Variables successfully updated in MY_TABLE dataset");
console.log(results);
},
error: function(error) {
console.log("Error when saving variables in MY_TABLE dataset");
console.log("Error " + error.code + ": " + error.message);
}
})
},
error: function(error) {
console.log("There was an error when running function MY_FUNCTION()");
console.log(error);
}
});
});