我想创建一个嵌套对象,并在上层之前保存每个最低级别(以便正确创建我的嵌套对象)..
目前这是我的非工作代码。我听说要使它工作,我不得不使用Promises。我陷入困境,因为我不知道如何在我的for循环中启动承诺
Parse.Cloud.define("test", function(request, response) {
var Test0 = Parse.Object.extend("Test0");
var test0 = new Test0();
var array0 = new Array();
for (i = 0; i < 10; i++) {
var Test1 = Parse.Object.extend("Test1");
var test1 = new Test1();
var array1 = new Array();
for (j = 0; j < 10; j++) {
var Test2 = Parse.Object.extend("Test2");
var test2 = new Test2();
test2.set("foo","bar");
array1.push(test2);
test2.save()
}
test1.set("foo","bar");
test1.set("array1",array1);
array0.push(test1);
test1.save();
}
test0.set("foo","bar");
test0.set("array0", array0);
test0.save(null, {
success: function(result) {
response.success("success");
},
error: function(result, error) {
alert('Failed to create new object, with error code: ' + error.message);
response.error("error");
}
});
});
我应该如何修改此代码,以便我的test1保存仅在其所有test2子项已正确终止自己的保存时发生?我将对test0应用相同的逻辑