query.off(‘value’) query.on(‘child_added’, function(child){}) query.on(‘child_removed’, function(child){}) query.on(‘child_moved’, function(child){}) query.on(‘child_changed’, function(child){}) A query sends events when its results change. We can listen to child CRUD events and an even on any value change.
a DataSnapshot var ref = firebase.database().ref("users/ada"); ref.once("value").then(function(snapshot) { var name = snapshot.child("name").val(); // { first: "Ada", last: "Lovelace"} var firstName = snapshot.child("name/first").val(); // "Ada" var lastName = snapshot.child("name").child("last").val(); // "Lovelace" var age = snapshot.child("age").val(); // null });
ref = firebase.database().ref("users"); ref.once("value").then(function(snapshot) { snapshot.forEach(function(childSnapshot) { var key = childSnapshot.key; // childData will be the actual contents of the child var childData = childSnapshot.val(); }); });
usersRef.set({ taro: “Taro Yoshida”, tetsuri: “Tetsuri Moriya” }) usersRef.on(‘child_removed’, child => alert(“Delete user” + child.val()) ) usersRef.child(“tetsuri”).remove() Trigger an event when a child node is removed from the referenced node.
database, hosting ✔ database: rules ready to deploy. i hosting: preparing public directory for upload... ✔ hosting: 2 files uploaded successfully i starting release process (may take several minutes)... ✔ Deploy complete! Hosting Site: https://megakanban.firebaseapp.com Dashboard: https://console.firebase.google.com/project/megakanban/overview Visit the URL above or run firebase open