Firebase - 批量删除子节点 [英] Firebase -- Bulk delete child nodes
本文介绍了Firebase - 批量删除子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用reactFire,Firebase和reactJS构建一个简单的待办事项应用程序。我遇到的问题是当我尝试批量删除列表中的完整条目。
componentWillMount:function(){
this.ref = Firebase.database()。ref(items / );
this.bindAsArray(this.ref,items);
this.ref.on('value',this.handleDataLoaded);
for(var this in this.state.items){
var key = items [i] ['。key'];
if(items [i] .done){
this.ref.child(key).remove();
循环过早结束,也就是在删除所有完成的条目之前,因为渲染函数被调用。
解决方案您可以使用多位置更新一次删除所有已完成的商品:
var updates = {};
for(var this in this.state.items){
var key = items [i] ['。key'];
if(items [i] .done){
updates [key] = null; //设置值为空删除键
$ b $ this.ref.update(updates);
I am building a simple todo app using reactFire, Firebase, and reactJS. The problem I am running into is when I try to bulk delete completed entries in the list.
componentWillMount: function() {
this.ref = Firebase.database().ref("items/");
this.bindAsArray(this.ref, "items");
this.ref.on('value', this.handleDataLoaded);
}
for (var i in this.state.items) {
var key = items[i]['.key'];
if(items[i].done){
this.ref.child(key).remove();
}
}
The loop ends prematurely i.e. before deleting all the completed entries, because the render function is called.
解决方案 You can delete all completed items in one go by using a multi-location update:
var updates = {};
for (var i in this.state.items) {
var key = items[i]['.key'];
if(items[i].done){
updates[key] = null; // setting value to null deletes the key
}
}
this.ref.update(updates);
这篇关于Firebase - 批量删除子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文