【问题标题】:How to join two paths and display to data list (Firebase Database and Ionic 2)如何连接两条路径并显示到数据列表(Firebase 数据库和 Ionic 2)
【发布时间】:2018-09-04 00:24:15
【问题描述】:
如何在 ionic 2 中加入 2 个路径 firebase 数据库。我有 2 个路径,“/Member/joinGroup”和“/Group”。当我在“/Member/joinGroup”上获得组 ID 时,我想显示信息组。我将在列表数据视图中显示数据。
下面是路径栏
Group
-123
-groupAdmin: test@gmail.com
-groupName: test
-groupPhoto: test.jpg
-456
-groupAdmin: test_456@gmail.com
-groupName: test 456
-groupPhoto: test1.jpg
Member
-member1
-memberName: james
-memberPhoto: james.jpg
-memberEmail: test@gmail.com
-joinGroup
-join1
-groupId: 123
-join2
-groupId: 456
【问题讨论】:
标签:
typescript
firebase
firebase-realtime-database
ionic2
【解决方案1】:
我得到了答案,这是代码
ionViewDidLoad() {
var personRef: firebase.database.Reference = firebase.database().ref().child(`Member/`+user.id+`/JoinGroup/`);
var groupRef: firebase.database.Reference = firebase.database().ref().child(`Group/`);
personRef.on('child_added', snap => {
groupRef.child(snap.val().groupId).once('value', grup =>{
//the result
this.allmygroups.push(grup.val());
});
});
}
别忘了声明变量 allmygroups
public allmygroups= [];
并在 html ionic 上显示结果
<ion-item *ngFor="let grup of allmygroups">
<ion-avatar item-start>
<img [src]=grup.groupPhoto>
</ion-avatar>
<h2>{{grup.groupName}}</h2>
</ion-item>