2016-09-18 99 views
1

而是從Driver的子數據設置爲null的..我想那個特定child被刪除。如何刪除特定的孩子在火力地堡(安卓)

這是我的示例代碼。

driverRef = new Firebase(Config.FIREBASE_URL_DRIVER); 
        Query pendingBus = driverRef.orderByChild("busNum").equalTo(busNum); 
        pendingBus.addListenerForSingleValueEvent(new ValueEventListener() { 
         @Override 
         public void onDataChange(DataSnapshot dataSnapshot) { 
          for (DataSnapshot snapshot : dataSnapshot.getChildren()) { 
           String busnumber = snapshot.child("busNum").getValue().toString(); 
           String empID = snapshot.child("empId").getValue().toString(); 

           if (busnumber.equals(busNum)) { 

            snapshot.getRef().child("age").setValue(""); 
            snapshot.getRef().child("busNum").setValue(""); 
            snapshot.getRef().child("driversName").setValue(""); 
            snapshot.getRef().child("empId").setValue(""); 
            snapshot.getRef().child("latitude").setValue(""); 
            snapshot.getRef().child("longitude").setValue(""); 
            snapshot.getRef().child("password").setValue(""); 
            snapshot.getRef().child("username").setValue(""); 
} 
} 

,這是該方法的輸出setValue Output

+2

請發佈你的數據庫結構。將null設置爲子項的值與刪除子項相同 – Wilik

回答

3

而不是使用setValuenull 我用.removeValue 例:snapshot.getRef().child("age").removeValue();

0

這對我來說

databaseReference = databaseReference.child("Users").child(mobile); 
databaseReference.setValue(null); 
工作