angular - 无法从 firebase 实时数据库中获取键值
问题描述
first.Component.html
<div class="col-md-3">
<button type="button" routerLink="editlots" class="btn btn-info" style = "font-size:
15px; text-align: center; margin:0 auto; display: block;">View Lots
</button>
</div>
second.component.html
<tr *ngFor="let it of lot$ | async">
<td> {{it.alias}} </td>
<td> {{it.area}} </td>
<td> {{it.price}} </td>
</tr>
在 plats/bigfork/lots 中,bigfork 是 lot 的父键,但我也有其他键,其中包含与具有相同数据的 lot 相同的子键。所以我想制作一个动态来代替 bigfork,这样我就可以访问关于我点击的特定按钮的数据。
第二个组件.ts
this.itemRef = db.list('/plats/bigfork/lots');
this.lot$ = this.itemRef.snapshotChanges().map(actions => {
return actions.map(action => ({
key: action.payload.key,
...action.payload.val()
}));
});
Firebase 数据库
{
"key": "bigfork",
"bg": "Background URL ",
"cover": "https://",
"description": "The conservation",
"footer": {
"address": "\t\t",
"companyName": "Companys",
"email": "user@email.com",
"favicon": "https:",
"phone": "111.1111.111",
"website": "https://www.facebook.com/#"
},
"header": {
"logo": "https:",
"title": "Preserve"
},
"lots": [
{
"address": "",
"alias": "113",
"area": "",
"assignedTo": "Available",
},
{
"address": "",
"alias": "112",
"area": "",
"assignedTo": "Available",
}],
{
"key": "cdl",
"bg": "Background URL ",
"cover": "https://",
"description": "The conservation",
"footer": {
"address": "\t\t",
"companyName": "Companys",
"email": "user@email.com",
"favicon": "https:",
"phone": "111.1111.111",
"website": "https://www.facebook.com/#"
},
"header": {
"logo": "https:",
"title": "Preserve"
},
"lots": [
{
"address": "",
"alias": "113",
"area": "",
"assignedTo": "Available",
},
{
"address": "",
"alias": "112",
"area": "",
"assignedTo": "Available",
}],
解决方案
您需要使用查询:
this.itemRef = db.list('/plats', ref => ref.orderByChild('lots').equalTo('lots'))
这样,您可以使用孩子的值来获取数据库中的不同键。
推荐阅读
- c# - 尝试使用 async/await 时的问题
- google-cloud-platform - Cloud Workflows:TypeError:字典键必须是字符串;得到:int
- android - 保持 webview 在后台播放音频
- typescript - React-Native-Reanimated 和 React-native
- r - 根据两个数据框中的列有条件地替换值
- java - 如何在eclipse中自动搜索maven依赖?
- c++ - 在不破坏现有代码的情况下添加新枚举
- python - 使用 python - tkinter 设置根窗口的单一维度的方法?
- json - Ansible 漂亮的打印 json
- .net - 在云端混淆应用程序设置文件,但允许本地应用程序开发