简体   繁体   English

是否可以从连接到 Firestore DB 的 RecyclerView 中临时删除项目?

[英]Is it possible to temporarily remove an item from RecyclerView that is connected to Firestore DB?

On the online voting system that I am currently working on, I am preparing for the voting feature.在我目前正在开发的在线投票系统上,我正在准备投票功能。 I plan to remove an item from the RecyclerView that the user has already voted on but in a way that it does not remove it from the Firestore database itself.我计划从用户已经投票的 RecyclerView 中删除一个项目,但不会从 Firestore 数据库本身中删除它。 Is there a way to do that?有没有办法做到这一点? If not, is there any workaround to make my concept work?如果没有,是否有任何解决方法可以使我的概念发挥作用? Thank you in advance for the responses.预先感谢您的答复。

I plan to remove an item from the RecyclerView that the user has already voted on but in a way that it does not remove it from the database itself.我计划从用户已经投票的 RecyclerView 中删除一个项目,但不会从数据库本身中删除它。

The simplest solution would be to add a field of type boolean with the default value of false, into each document.最简单的解决方案是在每个文档中添加一个默认值为 false 的 boolean 类型的字段。 You can simply call it "deleted".您可以简单地称其为“已删除”。 When you want to perform a delete operation, don't remove the document from the database, rather change its value from false to true.当您要执行删除操作时,不要从数据库中删除文档,而是将其值从 false 更改为 true。

If you want to have a temporary removal, you might also consider moving a document from a location to another .如果您想要临时删除,您还可以考虑将文档从一个位置移动到另一个位置

If not, is there any workaround to make my concept work?如果没有,是否有任何解决方法可以使我的概念发挥作用?

You can also use Cloud Functions , to trigger a function that contains a particular logic, when a delete operation takes place.您还可以使用Cloud Functions ,在发生删除操作时触发包含特定逻辑的函数。

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

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