2016-07-07 88 views
0

我開始詳細瞭解Firebase,並嘗試創建簡單的數據庫。從Firebase數據庫中刪除用戶

我遵循從網站的所有步驟,我成功地在數據庫中添加成員。

但是...現在,有必要了解如何刪除用戶。

這裏是我的代碼,添加和刪除用戶:

<!DOCTYPE html> 
<html> 
    <head> 


    </head> 
    <body> 
     <button onclick="saveData()">Save Data</button> 
     <button onclick="printData()">Print Data</button> 
     <button onclick="printData2()">Print Data2</button> 
     <button onclick="remove()">Remove</button> 
     <script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script> 
     <script> 
     var ref = new Firebase("https://projecttest-9aee9.firebaseio.com/web/saving-data/fireblog"); 
     var usersRef = ref.child("users"); 
     function saveData(){ 
     usersRef.set({ 
      alanisawesome: { 
      date_of_birth: "June 23, 1912", 
      full_name: "Alan Turing" 
      }, 
      gracehop: { 
      date_of_birth: "December 9, 1906", 
      full_name: "Grace Hopper" 
      } 
     }); 
     } 
     function printData(){ 

     usersRef.on("value", function(snapshot) { 
     console.log(snapshot.val()); 
     }, function (errorObject) { 
     console.log("The read failed: " + errorObject.code); 
     }); 
     } 
     function printData2(){ 

     ref.child("users/gracehop/date_of_birth").on("value", function(snapshot) { 
     console.log(snapshot.val());//"December 9, 1906" 
     }, function (errorObject) { 
     console.log("The read failed: " + errorObject.code); 
     }); 
     } 


     function remove(){ 
        ref.removeUser({ 
        alanisawesome: { 
        date_of_birth: "June 23, 1912", 
        full_name: "Grace Hopper" 
            } 

        }); 
      } 
     </script> 
    </body> 
</html> 

如果是刪除用戶功能的問題?

謝謝你的幫忙!

回答

2

第一個removeUser沒有在任何地方定義。其次,我不認爲你在remove()中使用正確的ref,你應該使用usersRef

嘗試使用user.remove()方法。

the User API參考:

刪除和體徵了用戶。

重要提示:這是一個安全敏感的操作,需要的 用戶在最近簽署如果這一要求得不到滿足,問 用戶再次進行身份驗證,然後調用 firebase.User#重新認證。

如果你想刪除對應於用戶的數據庫節點,你可以做這樣的事情:

usersRef.remove() 
    .then(function() { 
    console.log("Remove succeeded.") 
    }) 
    .catch(function(error) { 
    console.log("Remove failed: " + error.message) 
    }); 
+0

VAR REF =新的火力地堡(「https://projecttest-9aee9.firebaseio.com /網絡/保存數據/ fireblog「); ref.remove({alanisawesome:{ date_of_birth:「1912年6月23日」, 全名:「Alan Turing」 } }); –

+0

也許......類似的東西? Thaanks尋求幫助! –

+1

就是這樣!再次詛咒你!祝你有美好的一天:) –