简体   繁体   English

如何使用 reactjs 删除实时数据库(firebase v9)中的所有真实值?

[英]How to remove all true value in Realtime database (firebase v9) using reactjs?

How can I delete all the true value in the realtime database?如何删除实时数据库中的所有真实值?

firebase 实时数据库

this is my code but it can only delete a certain item.这是我的代码,但它只能删除某个项目。 How can I Make this to remove all items that have a "true" value.我怎样才能使它删除所有具有“真实”值的项目。

const removeTodo = (uid) => {
 remove(ref(db, `/${auth.currentUser.uid}/${uid}`))
 .then(alert("Todo deleted."))
 .catch((error) => console.error(error));
};

You first need to get all the RTDB nodes which have the completed sub-node set to true by following the documentation on how to filter data in the RTDB .您首先需要按照有关如何过滤 RTDB 中的数据的文档来获取所有已completed子节点设置为true的 RTDB 节点。

Then, for each of these nodes, you need to delete it.然后,对于这些节点中的每一个,您需要将其删除。 Since there are probably several nodes to delete, you can use the technique shown in the doc for simultaneously writing to specific nodes.由于可能有几个节点要删除,您可以使用文档中显示的技术同时写入特定节点。 And since you want to delete the nodes, you have to specify null as the value to be written for each node.并且由于要删除节点,因此必须将null指定为要为每个节点写入的值。


I let you implement the corresponding code.我让你实现相应的代码。 If you still encounter problems with your code, modify your question to show it together with the debugging details and, then, we (ie the community) will be able to help you further.如果您的代码仍然遇到问题,请修改您的问题以将其与调试详细信息一起显示,然后,我们(即社区)将能够为您提供进一步的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM