简体   繁体   English

如何显示 Firebase 数据库中的数据?

[英]How can I display data from Firebase database?

In the application, you can add your bank to the Firebase database.在应用程序中,您可以将您的银行添加到 Firebase 数据库。 When you click on the "Add Bank" button, the bank is saved to the database.当您单击“添加银行”按钮时,该银行将保存到数据库中。 I need to display cards with added banks on the screen.我需要在屏幕上显示添加了银行的卡片。 How can i do this?我怎样才能做到这一点? Now I am reading data from the database and it comes in the form of an object:现在我正在从数据库中读取数据,它以对象的形式出现:

在此处输入图像描述

Code for read data:读取数据的代码:

 const getBanksFunc = () => { const bankRef = ref(database, "banks/"); onValue(bankRef, (snapshot) => { const data = snapshot.val(); }); };

Firebase's documentation covers this: Firebase 的文档涵盖了这一点:

https://firebase.google.com/docs/database/web/read-and-writehttps://firebase.google.com/docs/database/web/read-and-write

import { getDatabase, ref, onValue} from "firebase/database";

const db = getDatabase();
const starCountRef = ref(db, 'posts/' + postId + '/starCount');
onValue(starCountRef, (snapshot) => {
  const data = snapshot.val();
  updateStarCount(postElement, data);
});

In your case, a for .. in loop could work:在您的情况下, for .. in 循环可以工作:

for(let key in data) {
    const { bankName, interestRate, loanTerm, maximumLoan, minimumDownPayment } = data[key];
    ... do whatever you need
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM