我使用以下代码获取事件列表:
eventsRef: AngularFireList<object[]>;
this.eventsRef = this.db.list('events');
this.events = this.eventsRef.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
我还想获得参加每个活动的嘉宾人数。类似于我下面的内容,使用每个事件中的c.payload.key
,但是我不确定如何向每个事件对象中添加goingCount
。现在它们全为0,因为attending
列表中的值位于返回值之后。
this.events = this.eventsRef.snapshotChanges().map(changes => {
let goingCount = 0;
console.log(changes)
changes.map(c => {
this.db.list(`attending/${c.payload.key}`).valueChanges()
.subscribe(data => {
console.log(data.length)
})
})
return changes.map(c => ({ key: c.payload.key, goingCount: goingCount, ...c.payload.val() }));
});