gpt4 book ai didi

javascript - 尝试更新和删除多个位置时未调用/触发返回的 Pomises Angular Firebase Web api

转载 作者:行者123 更新时间:2023-12-03 03:15:40 27 4
gpt4 key购买 nike

删除帖子时尝试设置多个定位删除。

但是问题该方法不会继续执行以下代码行:const deleteFromDatabase = this.db.ref().update(updateObject);

对如何实现这个逻辑画一个空白。尽管超出了那行代码,我怎样才能让它遵循呢?例如,当有 storageUri(图片和拇指)时,它似乎没有达到返回 Promise.all 的 if 条件

deletePost(postId, pictureStorageUri, thumbStorageUri): Promise<any> {
console.log(`Deleting ${postId}`);

// CONSTRUCT/DEFINE update object for real-time database data deletion
const updateObject = {};
updateObject[`/posts/${postId}`] = null;
updateObject[`/people/${this.currentUser.uid}/posts/${postId}`] = null;
updateObject[`/feed/${this.currentUser.uid}/${postId}`] = null;
updateObject[`/comments/${postId}`] = null;
updateObject[`/likes/${postId}`] = null;

// DEFINE/CALL deleteFromDatabase promise
const deleteFromDatabase = this.db.ref().update(updateObject);

// IF Picture Uris DEFINE/CALL storage delete promises
if (pictureStorageUri) {
const deleteFullFromStorage = this.storage.refFromURL(pictureStorageUri).delete();
const deleteThumbFromStorage = this.storage.refFromURL.delete();
console.log('promise being called');
return Promise.all([deleteFromDatabase, deleteFullFromStorage, deleteThumbFromStorage]);
}

// RETURNS this promise if no picture uris
return deleteFromDatabase;
}

最佳答案

如果您想从 if 语句返回某些内容,您的代码需要如下所示:

deletePost(postId, pictureStorageUri, thumbStorageUri): Promise<any> {
console.log(`Deleting ${postId}`);

// CONSTRUCT/DEFINE update object for real-time database data deletion
const updateObject = {};
updateObject[`/posts/${postId}`] = null;
updateObject[`/people/${this.currentUser.uid}/posts/${postId}`] = null;
updateObject[`/feed/${this.currentUser.uid}/${postId}`] = null;
updateObject[`/comments/${postId}`] = null;
updateObject[`/likes/${postId}`] = null;

// DEFINE/CALL deleteFromDatabase promise
let promise = this.db.ref().update(updateObject);

// IF Picture Uris DEFINE/CALL storage delete promises
if (pictureStorageUri) {
const deleteFullFromStorage = this.storage.refFromURL(pictureStorageUri).delete();
const deleteThumbFromStorage = this.storage.refFromURL.delete();
console.log('promise being called');
promise = Promise.all([promise, deleteFullFromStorage, deleteThumbFromStorage]);
}

// RETURNS this promise if no picture uris
return promise;
}

只是为了给您一个想法,也许您可​​以使用另一个辅助变量来使命名更清晰。

关于javascript - 尝试更新和删除多个位置时未调用/触发返回的 Pomises Angular Firebase Web api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46779043/

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