如何使用javascript从Firebase中检索数据? [英] how can I retrieve data from Firebase in web using javascript?

查看:83
本文介绍了如何使用javascript从Firebase中检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Firebase检索数据并将其添加到html页面?
,以及如何自动打开新的html页面以添加我正在检索的数据?
示例:
我从firbase获得了这门课程:



当我单击此课程时,我想看到有关此课程的所有数据,如下所示:



有人可以帮我吗?!
我不喜欢这种样式,只是我想知道如何在所有课程中以相同的样式检索数据并将其添加到新的html页面中。

解决方案

您可以像这样从Firebase实时数据库中检索数据:

  //导入管理SDK 
var admin = require( firebase-admin);

//获取对我们帖子的数据库引用
var db = admin.database();
var ref = db.ref(路径/的/您的/信息);

//附加异步回调以在我们的帖子引用中读取数据。
ref.on( value,function(snapshot){
console.log(snapshot.val ());
},函数(errorObject){
console.log(读取失败: + errorObject.code);
});

请参见此处的官方文档


注意:需要Node。 js / npm



How can I retrieve data from Firebase and add to html page? and, How can I open new html pages automatically to add the data I was retrieving it? example: I have this course from firbase:

this key I was pushing it . and I want my website like this course :

When I click this courses I want to see all data about this course like this :

Can anyone help me ?! I won't like this style just I want to know how can i retrieve data and add it in new html pages in the same style in all courses .

解决方案

You can retrieve data from a firebase realtime database like so:

// Import Admin SDK
var admin = require("firebase-admin");

// Get a database reference to our posts
var db = admin.database();
var ref = db.ref("path/of/your/information");

// Attach an asynchronous callback to read the data at our posts reference
ref.on("value", function(snapshot) {
  console.log(snapshot.val());
}, function (errorObject) {
  console.log("The read failed: " + errorObject.code);
});

See Official Documentation here

Note: requires Node.js / npm

这篇关于如何使用javascript从Firebase中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆