最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Firebase I want to console log my firebase data - Stack Overflow

programmeradmin1浏览0评论

Simple question I hope you good people can help me with.

I'm using Firebase and I can display my firebase data on the page using:

var dbRef = firebase.database().ref().child('jumbotron/header');
dbRef.on('value', snap => container.innerText = snap.val());

But when I try to: console.log(dbRef) It displays as an object. I think this is because the reference is a URL. How can I console.log or print my firebase data as a string and eventually place it on my page using vanilla javascript. I can't find the solution in the FB documentation and there aren't any tutorials on the Google FB.

Any help is much appreciated. Thanks, All

Simple question I hope you good people can help me with.

I'm using Firebase and I can display my firebase data on the page using:

var dbRef = firebase.database().ref().child('jumbotron/header');
dbRef.on('value', snap => container.innerText = snap.val());

But when I try to: console.log(dbRef) It displays as an object. I think this is because the reference is a URL. How can I console.log or print my firebase data as a string and eventually place it on my page using vanilla javascript. I can't find the solution in the FB documentation and there aren't any tutorials on the Google FB.

Any help is much appreciated. Thanks, All

Share Improve this question edited Jul 14, 2016 at 14:53 Frank van Puffelen 600k85 gold badges890 silver badges860 bronze badges asked Jul 14, 2016 at 4:49 Moe-JoeMoe-Joe 1,0303 gold badges15 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

As the name implies dbRef is a reference to the data, it is not the data itself.

When you attach a listener to the reference with on(), you will get a snapshot of the data at that location. You can get the value from this snapshot and print it:

var dbRef = firebase.database().ref().child('jumbotron/header');
dbRef.on('value', snapshot => {
  console.log(snapshot.val());
});
发布评论

评论列表(0)

  1. 暂无评论