[英]Parse.com javascript sdk nested save
我知道這在 Parse 的 Java SDK 中是可能的。 但是考慮到我有一個解析對象 A 將指向另一個對象 B 將指向另一個對象 C 的情況。
通過正確設置所有字段,是否可以只保存對象 A 並自動保存嵌套對象
謝謝,卡蘭沙
Parse 中的對象在保存之前不能設置為字段。
您需要先保存 C,然后是 B,然后是 A。
這可以通過 Parse 承諾來實現。
var C = Parse.Object.extend("C"); // Or whatever objects they are
var B = Parse.Object.extend("B");
var A = Parse.Object.extend("A");
C.save().then(function()
{
B.set("C", C);
return B.save();
}).then(function()
{
A.set("B", B);
return A.save();
}).then(function()
{
console.log("All saved successfully!");
});
實際上,從 2020/1 開始,您可以 一次全部保存它們。
在 save(opts) 中使用可選參數。
const Child = Parse.Object.extend("Child");
const child = new Child();
const Parent = Parse.Object.extend("Parent");
const parent = new Parent();
parent.save({ child: child });
// Automatically the object Child is created on the server
// just before saving the Parent
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.