gpt4 book ai didi

javascript - Parse.com 云代码 afterSave() 错误 : "Uncaught Tried to save an object with a pointer to a new, unsaved object."

转载 作者:行者123 更新时间:2023-12-03 11:10:37 25 4
gpt4 key购买 nike

上下文

我在 Web 应用程序的后端之后使用 Parse.com。我遇到的问题与云代码有关。

用户完成其个人资料后,我想调用 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);
}
});
});

最佳答案

您的描述中可能缺少一些信息,但我希望我以前的经验可以提供帮助:

上次出现此错误时,我执行了以下操作:

上下文:在查询回调中,结果变量为 res

var MyParseClass = Parse.Object.extend("MyParseClass");
var newObject = new MyParseClass();

res.set("pointerFieldToMyParseClass",newObject);

res.save();

在此示例中,newObject 不存在于该函数的范围之外,因此您必须先保存它:

var MyParseClass = Parse.Object.extend("MyParseClass");
var newObject = new MyParseClass();

newObject.save({
success:function(savedObject){

res.set("pointerFieldToMyParseClass",newObject);
res.save();

},error:function(e){}});

关于javascript - Parse.com 云代码 afterSave() 错误 : "Uncaught Tried to save an object with a pointer to a new, unsaved object.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27613500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com