如何删除具有指定标题的firebase中的特定记录 [英] How to delete specific record in firebase having specified Title

查看:37
本文介绍了如何删除具有指定标题的firebase中的特定记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当时在Web App中使用Firebase数据库,并且有类似这样的数据:

I was using Firebase Database in Web App, and have data like this yet:

如何删除标题中带有"Apple"的整个记录​​(如图所示)?

How can i delete the entire record having "Apple" in title (marked in picture)?

我写了下面的代码,但是没有用.

I wrote the below code but it's not working.

请帮助.

var abc = firebase.database().ref('firebase-test');
var key_to_delete = 'Apple';
var query = abc.orderByChild('KISNx87aYigsH3ILp0D').equalTo(key_to_delete);
query.on('child_added', function(snapshot)
{
    snapshot.ref.remove();
});

在控制台上没有给我任何错误.

It's not giving me any error in Console.

推荐答案

您正在对错误的属性进行排序/过滤.您具有他的 title 属性的值,因此应在其上订购:

You're ordering/filtering on the wrong property. You have the value of he title property, so should order on that:

var abc = firebase.database().ref('firebase-test');
var key_to_delete = 'Apple';
var query = abc.orderByChild('title').equalTo(key_to_delete);
query.on('child_added', function(snapshot)
{
    snapshot.ref.remove();
});

或者,由于您知道要删除的项目的键,因此您也可以在不查询的情况下删除该项目:

Alternative, since you know the key of the item you want to delete, you can also delete that item without a query:

var abc = firebase.database().ref('firebase-test');
abc.child("KISNx87aYigsH3ILp0D").remove();

这篇关于如何删除具有指定标题的firebase中的特定记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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