1

I have the following problem. The code recognizes that there is something and shows all the entries, but not the content, but only displays [object object]. I really want to read everything that is in the category "abgeschlosseneAuftraege" and also all subcategories. But for now I try to read at least 1 entry. I would be very grateful for help.

firebase.database().ref("/abgeschlosseneAuftraege").on('value', function(snapshot){
  let elm = document.getElementById("data");
  elm.innerHTML = '';

  snapshot.forEach(function(childSnapshot){
    var childKey = childSnapshot.key;
    var childData = childSnapshot.val();
    elm.innerHTML += childData['Accepted'];
  })
})
    getData();

Firebase

11
  • childSnapshot.val() must be returning an object. not a string. Commented Sep 25, 2019 at 20:42
  • [object Object] is what you get when you use an object where a string is required. So childData['Accepted'] must be an object. What does console.log(childData['Accepted']) show? Commented Sep 25, 2019 at 20:54
  • @rlemon childSnapthot.val() has to be an object so you can use childData['Accepted']. Commented Sep 25, 2019 at 20:55
  • yea duh. that was a brain fart comment on my part. I meant childData.Accepted must be an object. my bad Commented Sep 25, 2019 at 20:59
  • @Barmar elm.innerHTML += console.log(childData['Accepted']); elm.innerHTML + = console.log (childData ['Accepted']); shows all entries, but instead of object object it shows undefined undefinedundefined ... Commented Sep 25, 2019 at 21:04

1 Answer 1

1

childData['Accepted']; is an object, not a string. If you want to see a representation of it, use JSON.stringify().

    elm.innerHTML += JSON.stringify(childData['Accepted']);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.