Firebase - 用于set()而不是update()的良好用例 [英] Firebase - good use case for set() instead of update()

查看:124
本文介绍了Firebase - 用于set()而不是update()的良好用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Firebase的应用中构建了创建,更新和删除操作。关于这个答案关于 set() update(),@ jmk2142建议在firebase中创建,更新和删除一个项目都可以用 update()

除了语义/理解代码的目的,有没有什么好的理由不使用 update()所有这些?

解决方案

如果要替换位置中的整个值,则需要使用<$如果要更新位置下的特定属性或路径,请使用

update()


I'm building create, update and delete operations in my app that uses Firebase. Regarding this answer on a question about the difference between set() and update(), @jmk2142 suggested that creating, updating and deleting an item in firebase could all be done with update().

Apart from semantics / understanding the purpose of the code, is there any good reason NOT to use update() for all of these?

解决方案

If you want to replace the entire value in a location, you'll want to use set().

If you want to update specific properties or paths under a location, use update().

这篇关于Firebase - 用于set()而不是update()的良好用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆