2016-07-07 90 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

就是这样!再次诅咒你!祝你有美好的一天:) –