문제

I'm trying to read firebase data and then print the data to the console, but nothing makes it to the console.

function readData(){
var listRef = new Firebase('https://----.firebaseIO.com/');

    listRef.on('child_added', function(snapshot) {

    var msgData = snapshot.val();
    console.log("Snapshot : " + msgData.message);

    });//end snapshot


}//end readData

my firebase data looks like. This is right under the root.

{
"-J75NmiNt3blUhVDCWbc" : {
"from" : "Blah",
"message" : "Blah"
},
"-J75N2bNbDZpshEBG1yS" : {
"from" : "Jackson",
"message" : "BLAH  BlaH"
},
"-J75PCsjFlbDQ3g9vKyb" : {
"from" : "fff",
"message" : "fff"
},
"-J75MvQQpRBB6s-l3KrQ" : {
"from" : "",
"message" : ""
},
"-J75OHX7rdE1K8wpvZOt" : {
"from" : "fff",
"message" : "ff"
}
} //end
도움이 되었습니까?

해결책

EDIT: My original answer was completely missing question, rewritten for further smiting

Are you sure that you are getting the data within your Event? It would gracefully fail. Step through the debugger and make sure you are getting your actual object passed correctly. From their example on the chat tool They are binding to an event that pushes to the listRef object like this:

$('#messageInput').keypress(function (e) {
  if (e.keyCode == 13) {
    var name = $('#nameInput').val();
    var text = $('#messageInput').val();
    messagesRef.push({name:name, text:text});
    $('#messageInput').val('');
  }
});

My guess is that your snapshot variable is not accessible/null.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top