![](/img/trans.png)
[英]How to write data in Firebase Realtime Database as [custom key : value] in React?
[英](Firebase Realtime Database| React) How to add data to a firebase realtime database without key?
我想像这样构造我的数据,当我喜欢它时将 movieId 添加到愿望清单,但我不知道如何 go 。 我正在使用 push() 但它添加了一个生成的密钥,然后添加了我不想要的电影。 我怎样才能做到这一点?
添加第一个电影set(ref(db,`users/${auth.currentUser?.uid}/wishlist/`),{[movieId]:true})
添加后续电影的代码
const wishlistRef = ref(db, `users/${auth.currentUser?.uid}/wishlist`);
const newWishlistRef = push(wishlistRef);
set(newWishlistRef, {
[movieId]:true
});
这就是诀窍
const nodeRef = child(ref(db), `users/${auth.currentUser?.uid}/wishlist/` + movieId); // id = custom ID you want to specify
set(nodeRef, true )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.