Firebase-删除节点 [英] Firebase - Delete a node

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

问题描述

我正在构建离子+角度+火力地堡应用程序.我无法从Firebase集合中删除节点.我有一个html视图,该视图显示数组中的项目列表(使用ng-repeat).这是我的看法:

I am building an ionic+angular+firebase application. I am unable to delete a node from my firebase collection. I have an html view which displays a list of items from an array(using ng-repeat). This is how my view looks:

test@testmail.com : 23
fire@firemail.com : 784

我有一个删除按钮,它允许用户从数组中删除一个项目,而这又应从我的Firebase集合中删除该对象.我想使用事件ID来订购集合,然后删除具有bill:23和email:"test@testmail.com"的节点

I have a delete button which allows the user to delete an item from the array and this in turn should delete the object from my firebase collection. I want to order the collection using the eventid and then delete the node with bill:23 and email:"test@testmail.com"

Bill
-KMhWUkwDFwlRvqv0kDG
  bill: 23
  email: "test@testmail.com"
  eventid: **42539660**

-KN0_OUYJf_XQJSLPgmi
 bill: 784
 email: "fire@firemail.com"
 eventid: **42539660**

我可以使用查询获取所有带有特定eventid的账单:

I am able to get all the bills with a specific eventid using the query:

var id = 42539660;
billref.orderByChild('eventid').equalTo(id).on("value", function (snapshot) {
}

但是我不确定如何从此处继续删除特定节点.谢谢您的宝贵时间.

but i am not sure how to proceed from here to delete the specific node. Thanks for your time.

推荐答案

如果要删除查询匹配的节点:

If you want to delete the node that your query matches:

var id = 42539660;
billref.orderByChild('eventid').equalTo(id).on("value", function (snapshot) {
  snapshot.forEach(function(childSnapshot) {
    childSnapshot.ref.remove();
  });
}

或者,您可以使用 child_added 来消除循环的需要:

Alternatively you can use child_added to remove the need for a loop:

var id = 42539660;
billref.orderByChild('eventid').equalTo(id).on("child_added", function (snapshot) {
  snapshot.ref.remove();
}

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

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