如何删除/移除Firebase上的节点 [英] How to delete/remove nodes on Firebase
问题描述
我可以使用'.on(child_added)'来推送和检索数据,但'.remove() 不像它说的那样工作。根据API,
Firebase.remove() -
移除此Firebase位置处的数据。
删除的效果将立即可见。
然而,删除不是立即发生;只有当整个脚本完成运行。我需要删除,然后立即使用清除的树。
示例代码:
ref = new Firebase(myfirebase.com)// works
ref.push({key:val})// works
ref.on('child_added ',函数(快照){
//做东西
}); //作品
ref.remove()
//直到完成整个脚本/页面才会被删除
有一个类似的帖子这里,但我没有使用Ember库,即使如此,它似乎是一个解决方法,应该像API解释那样简单。
问题是您在Firebase的根目录调用 remove
:
ref = new Firebase(myfirebase.com)
ref.remove();
这是行不通的,因为您无法通过API删除整个Firebase。
你可以删除它下面的任何一个子。
ref。孩子(键)一个.remove();
I'm using Firebase for a web app. It's written in plain Javascript using no external libraries.
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() - 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.
Example code:
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
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.
The problem is that you call remove
on the root of your Firebase:
ref = new Firebase("myfirebase.com")
ref.remove();
This will not work, because you cannot remove an entire Firebase through the API.
You can remove any child under it though.
ref.child(key).remove();
这篇关于如何删除/移除Firebase上的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!