Firebase push()和set() [英] Firebase push() and set()

查看:98
本文介绍了Firebase push()和set()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些React代码来将文本推送到firebase,我已经看到了几种不同的方法。我认为不同之处是set()会覆盖位置的数据,而push会将它添加到已经存在的位置,但是我遇到了

I'm writing a bit of React code to push text to firebase and I've seen a couple different ways of doing this. I think the difference is set() overwrites the data at location while push will add it to the location under whatever is already there, however I then came across

this.ref.push().set({text: text});

使用两者,所以现在我有点困惑与set()相比和push()
感谢任何帮助

which uses both, so now I'm a bit confused what that does compared to just set() and push() Any help is appreciated

推荐答案

调用 ref.push()。 Firebase JavaScript SDK中的set({text:text})完全相同 ref.push({text:text})。这只是一种速记符号。

Calling ref.push().set({text: text}) in the Firebase JavaScript SDK does the exact same ref.push({text: text}). It's just a shorthand notation.

这篇关于Firebase push()和set()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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