我有以下Firebase数据库:
我只想检索一组Accounts
记录,然后将其与ng-repeat
绑定,如下所示:
<table>
<tr ng-repeat="account in accounts">
<td>{{ account.AccName }}</td>
<td>{{ account.AccStatus }}</td>
</tr>
</table>
我使用的是自动版本的Firebase引用和初始化,如下所示,因此此处未指定apiKey
和databaseURL
:
<!-- update the version number as needed -->
<script defer src="/__/firebase/6.2.4/firebase-app.js"></script>
<!-- include only the Firebase features as you need -->
<script defer src="/__/firebase/6.2.4/firebase-auth.js"></script>
<script defer src="/__/firebase/6.2.4/firebase-database.js"></script>
<script defer src="/__/firebase/6.2.4/firebase-messaging.js"></script>
<script defer src="/__/firebase/6.2.4/firebase-storage.js"></script>
<!-- initialize the SDK after all desired features are loaded -->
<script defer src="/__/firebase/init.js"></script>
当我对snapshot
进行简单检查时,它总是不存在(无论如何都没有运行时错误):
// ref("Accounts") is my root ref as shown in picture above
const accountsRef = firebase.database().ref("Accounts");
accountsRef.once("value").then(function (snapshot) {
if (snapshot.exists()) {
console.log(snapshot.val());
} else {
console.log("Snapshot not exist!");
}
})
我尝试了ref("/Accounts")
和ref("Accounts/")
,但是没有运气。抱歉,我是Firebase实时数据库的新手。我只想知道:
Accounts
数据库表检索记录集,并将其与ng-repeat
绑定,如上所示?OTK-001
是Accounts
表/集合中每个记录的唯一帐户代码。apiKey
和databaseURL
添加旧的Firebase配置? (注意:之前尝试过,无法正常工作。)任何帮助将不胜感激,在此先感谢您!
答案 0 :(得分:1)
Firestore查询如下所示
firestore的收集参考为
let collectionRef = firestore.collection('col/doc/subcollection');
获取数据是
async getAccountData() {
const snapshot = await firebase.firestore().collection('accounts').get()
return snapshot.docs.map(doc => doc.data());
}