【发布时间】:2021-01-05 23:29:51
【问题描述】:
我正在使用 Firestore 数据库在 Angular 中创建一个应用程序。 我必须使用不同的选择参数进行查询。
如何创建一个字符串,以便查询根据用户的选择而变化?
应用程序有一个包含以下字段的选择表单:
Date from
Date Until
status
Client
Seller
paymenttype
有多种可能的组合,想法是用已选择的字段构建一个字符串
例如:
在.ts中
if (typeof this.staTus != "undefined" && typeof this.paymenttype != "undefined" && typeof this.Client != "undefined" && typeof this.Seller != "undefined") {
strquery = '"order", ref => ref.where("DateOrder", ">=", "' + this.Datefrom + '").where("DateOrder", "<=", "' + this.DateUntil + '").where("idclient", "==", "' + this.Client + '").where("status", "==", "' + this.staTus + '").where("seller", "==", "' + this.seller + '").where("paymenttype", "in", "' + this.paymenttype + '").orderBy("DateOrder", "desc").limit(5000)';
this.orderServices.getOrdersRep(strquery).subscribe(ord => {
this.Ped_ = ord;
})
}
在服务中
getOrdersRep(strq?) {
this.ordersColletionrep = this.db.collection(strq);
this.ordersrep = this.ordersColletionrep.snapshotChanges().pipe(map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as Order;
return data;
})
}));
return this.ordersrep;
}
这种方式没有错误但对我不起作用,它不带数据
【问题讨论】:
标签: javascript angular firebase google-cloud-firestore