删除Firebase中的节点 [英] delete node in firebase

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

问题描述

开始阅读文档和其他文章,但是我无法删除节点.我试图通过一个值选择节点.

been reading docs and other posts but I am unable to remove a node. I am attempting to select the node by a value.

  var eventContactsRef = firebase.database().ref('events-contacts');
  eventContactsRef.orderByChild('eventContactId').equalTo(eventContactId);

然后在结果上调用remove方法

then call the remove method on the result

 eventContactsRef.remove(function (error) {
    console.log(error);
  });

除了错误值null之外,什么都没有发生.我使用的是最新的Firebase,大多数示例适用于旧版本,因此我不确定是否需要获取密钥,然后尝试删除该密钥作为参考?

nothing happens except a null error value. I am using the latest firebase, most examples are for older versions so I am unsure if I need to get the key and then attempt to delete with that as a reference?

这是第一次使用Firebase,因此我不确定是否正确保存了数据.这是要保存的代码.

This is the first time using firebase so I am not sure if I have saved the data correctly. here is code to save.

 var key = firebase.database().ref().child('event-contacts').push().key;
  var url = firebase.database().ref('/event-contacts/' + key);
  url.set(eventContacts);

和屏幕截图

推荐答案

您无法删除查询本身.您只能删除与查询匹配的结果.

You cannot remove a query itself. You can only remove the results that match a query.

var eventContactsRef = firebase.database().ref('events-contacts');
var query = eventContactsRef.orderByChild('eventContactId').equalTo(eventContactId);
query.on('child_added', function(snapshot) {
    snapshot.ref.remove();
})

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

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