【发布时间】:2016-07-07 14:27:34
【问题描述】:
我开始了解有关 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>
删除用户功能的问题在哪里?
感谢您的帮助!
【问题讨论】:
标签: javascript angularjs firebase firebase-realtime-database