【发布时间】:2017-02-17 17:36:15
【问题描述】:
我正在使用 React 和 Firebase 网络数据库。
在下面的代码中,dbRef 指向一个 Firebase 数据库树,其中包含一个 array 字符串。此数组的某些元素已被删除,导致索引为空。
[
"0": "first",
"1": "next",
"6": "skipped indexes 2 - 5"
]
我目前正在做:
dbRef.set([...currentList, newItem])
但是,我想确保传递给set 的数组没有任何null 索引。在 JS 中执行此操作的最佳方法是什么? (如果重要,我正在使用 babel)
【问题讨论】:
-
您不应该将数组存储在 Firebase 中,因为您尝试解决此问题的确切原因。见:firebase.googleblog.com/2014/04/…
-
@MathewBerg,感谢您指出这一点。我将改用对象。
标签: javascript reactjs web firebase firebase-realtime-database