我是 Cloud FireStore 的新手,并且一直在寻找很多天都没有结果的简单解决方案,我如何对来自 Observable Angular Firestore 的数组的某些字段值求和。我有一个行列表,我想要总和并获得总列,这是我的代码的一部分:
constructor(private afs: AngularFirestore, private router: Router, private route: ActivatedRoute) {
this.negocio = this.route.snapshot.queryParams['negocioId']
this.movtosCollectionRef = this.afs.collection('movtos', ref => ref.where('empresa', '==', this.negocio));
this.movtos$ = this.movtosCollectionRef.snapshotChanges().map(actions => {
return actions.map(action => {
const data = action.payload.doc.data() as Movtos;
const id = action.payload.doc.id;
return { id, ...data };
});
});
}
在我的模板中,我进行浏览:
<tbody>
<tr *ngFor="let item of movtos$ | async" [class.completed]="item.completed">
<td>{{ item.indate | date: 'dd/MM/yyyy - HH:mm:ss'}}</td>
<td>{{ item.concepto }} </td>
<td>{{ item.tipomov }} </td>
<td>{{ item.inuser }} </td>
<td>{{ item.importe | currency:'USD':true:'3.2-2' }}</td>
<td>
<a class="btn btn-info" (click)="editaEmpresa(item.id)" tooltip="Edita Movimiento" placement="top"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></a>
</td>
</tr>
</tbody>
我想得到 item.importe 字段的总和。有人知道怎么做这个吗?最好的问候, Caribesoft