function getMyData() { var msgName = document.getElementById('name').value; var newClientKey = database.ref().child('messages').push().key; database.ref('messages/' + newClientKey + '/name').get(msgName); window.alert(username); //document.write(starCountRef); }
// Try to read a message// var messageRef = firebase.database().ref('messages/');// messageRef.on('value', function(snapshot) {// updateStarCount(postElement, snapshot.val());// });
//Try to read users data-oncevar userId = firebase.auth().currentUser.uid;return firebase.database().ref('/users/' + userId).once('value').then(function(snapshot) { var name = snapshot.val().name; // ...});
function getMyData() { //1 code for getting messages because of auto-generated id
var messageRef = firebase.database().ref('messages/');
messageRef.forEach(function(secondsnapshot) {
var newClientKey = database.ref().child('messages').push().key;
var textname = database.ref('messages/' + newClientKey + '/name').getValue(msgName); window.alert(textname); });
}
Here is how I get that data from Firebase by taking a snapshot of the "hobbies" snapshot:
var hobbieList = document.getElementById('hobbieList');
objectRef = firebaseRoot.child('object');
objectRef.child('hobbies').on('child_added', function (snap) {
var li = document.createElement('li'); li.innerText = snap.val(); li.id = snap.key; hobbieList.appendChild(li);});
What I get returned is a list of hobbies, which I place in an unordered list.
I hope this helps you! Let me know, please :)
Thanks Ryan. Ill look these over. For the time being, I managed to get the data I needed but by looping through with for loop if child had a key. Id like to eventually learn how to actually get the key value.Then I went ahead and complicated things a bit more by trying to access a parent value (timeoff & timeon):
console.log("testing"); return firebase.database().ref('timeoff').once('value', function(snapshot){ console.log("hello"); window.alert(snapshot.val()); })
--
You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/e2NByQCW-NA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/5833a89e-7be2-4a55-b24a-c325f30a6cbf%40googlegroups.com.