如何删除/移除 Firebase 上的节点 [英] How to delete/remove nodes on Firebase

查看:22
本文介绍了如何删除/移除 Firebase 上的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Firebase 用于网络应用.它是用纯 Javascript 编写的,没有使用外部库.

I'm using Firebase for a web app. It's written in plain Javascript using no external libraries.

我可以使用 '.on("child_ added")' 来推送"和检索数据,但是 '.remove()' 并不能像它所说的那样工作.根据 API,

I can "push" and retrieve data with '.on("child_added")', but '.remove()' does not work the way it says it should. According to the API,

"Firebase.remove() -删除此 Firebase 位置的数据.子位置的任何数据也将被删除.删除的效果立马可见."

"Firebase.remove() - Remove the data at this Firebase location. Any data at child locations will also be deleted. The effect of the delete will be visible immediately."

然而,移除不会立即发生;只有当整个脚本完成运行时.我需要立即删除并使用清除的树.

However, the remove is not occurring immediately; only when the entire script is done running. I need to remove and then use the cleared tree immediately after.

示例代码:

ref = new Firebase("myfirebase.com") //works
ref.push({key:val}) //works

ref.on('child_added', function(snapshot){
//do stuff
}); //works

ref.remove()
//does not remove until the entire script/page is done

这里有一个类似的帖子,但我是不使用 Ember 库,即便如此,它似乎是一种解决方法,它应该像 API 解释的那样简单.

There is a similar post here but I am not using Ember libraries, and even so it seems like a workaround for what should be as simple as the API explains it to be.

推荐答案

问题是你在 Firebase 的根上调用了 remove:

The problem is that you call remove on the root of your Firebase:

ref = new Firebase("myfirebase.com")
ref.remove();

这将通过 API 删除整个 Firebase.

This will remove the entire Firebase through the API.

您通常希望删除它下面的特定子节点,您可以这样做:

You'll typically want to remove specific child nodes under it though, which you do with:

ref.child(key).remove();

这篇关于如何删除/移除 Firebase 上的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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