简体   繁体   English

如何在Firebase实时数据库中删除孩子的特定孩子?

[英]How delete the particular child of child in firebase realtime database?

I want to delete the particular child of a child in firebase realtime database. 我想在Firebase实时数据库中删除孩子的特定孩子。

I have added a picture of my database. 我已经添加了数据库图片。

I want to remove the highlighted child. 我要删除突出显示的孩子。

You can try this code. 您可以尝试此代码。

 Query query =  myRef.child("Purchase_Request").orderByChild("Chimney_Purchase");

    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot snap: dataSnapshot.getChildren()) {
                if(snap.getKey().equals("your_key")) {
                    snap.getRef().removeValue();
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e(TAG, "onCancelled", databaseError.toException());
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM