且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何删除具有指定标题的firebase中的特定记录

更新时间:2023-12-05 21:01:28

您正在对错误的属性进行排序/过滤.您具有他的 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();