好的,所以我尝试创建一个深层文件夹结构,然后循环遍历重复的文件夹名称并创建这样的承诺:
var promises = [];
_.each(files, function (file) {
promises.push(localFolder
.createFolderAsync(folder1Name, Windows.Storage.NameCollisionOption.OpenIfExists)
.then(function (folder1) {
return folder1.createFolderAsync(folder2Name, Windows.Storage.CreationCollisionOption.OpenIfExists);
})
.then(function (folder2) {
return folder2.createFileAsync(fileName, Windows.Storage.NameCollisionOption.replaceExisting)
})
);
});
return WinJS.Promise.join(promises);
问题是重复的文件夹,我认为OpenIfExists只会返回现有文件夹,但我最终会得到名为" folder1Name(1)"," folder1Name(2)&的文件夹#34;等使用FailIfExists也没有失败,所以我怀疑我的诺言链存在问题。
任何人都可以查明我做错了吗?
答案 0 :(得分:1)
第一个createFolderAsync调用的第二个参数应该是Windows.Storage。 CreationCollisionOption .openIfExists而不是NameCollisionOption。
var promises = [];
_.each(files, function (file) {
promises.push(localFolder
.createFolderAsync(folder1Name, Windows.Storage.CreationCollisionOption.openIfExists)
.then(function (folder1) {
return folder1.createFolderAsync(folder2Name, Windows.Storage.CreationCollisionOption.openIfExists);
})
.then(function (folder2) {
return folder2.createFileAsync(fileName, Windows.Storage.NameCollisionOption.replaceExisting)
})
);
});
return WinJS.Promise.join(promises);