-
-
Save bommels/4665eb03c53659dc89da6f9252c68591 to your computer and use it in GitHub Desktop.
Firebase: Get the parent of a snapshot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getParent(snapshot) { | |
// You can get the reference (A Firebase object) from a snapshot | |
// using .ref(). | |
var ref = snapshot.ref; | |
// Now simply find the parent and return the name. | |
return ref.parent.key; | |
} | |
var testRef = new Firebase("https://example.firebaseIO-demo.com/foo/bar"); | |
testRef.once("child_added", function(snapshot) { | |
// Should alert "Name of the parent: foo". | |
alert("Name of the parent: " + getParent(snapshot)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment