【发布时间】:2020-07-17 17:54:13
【问题描述】:
我正在使用 3 个搜索字段从我的 collection 获取结果。
如果this.tag 为空,我不希望此.where("tagarray", "array-contains", this.tag) 工作,同样如果this.dt 为空.where('lastActivityDate', '>=', this.dt) 不应该工作。 this.leadstage 也一样。
我该如何处理这种情况?
loadItems(){
this.firestore.collection('leads' , ref => ref
.where("tagarray", "array-contains", this.tag)
.where('lastActivityDate', '>=', this.dt)
.where("leadstage" , "==" , this.leadstage)
编辑 1
我这个函数的全部代码
loadItems(){
this.firestore.collection('leads' , ref => ref
.where("tagarray", "array-contains", "tag1") //tag success
.where('lastActivityDate', '>=', '07-APR-2020') //date success
.where("leadstage" , "==" , 'Prospect') // leadstage success, this is case sensitive
.limit(5)
).snapshotChanges()
.subscribe(response => {
if(!response.length){
console.log("no data available");
return false;
}
this.tableData = [];
for(let item of response){
var data = Object.assign(item.payload.doc.data(), {id : item.payload.doc.id})
this.tableData.push(data);
...
编辑 2
错误截图
编辑 3
当前代码
this.firestore.collection('leads' , (ref) => {
let query = ref;
if (this.tag) {
query = query.where("tagarray", "array-contains", this.tag)
}
if (this.dt) {
query = query.where('lastActivityDate', '>=', this.dt)
}
if (this.leadstage) {
query = query.where("leadstage" , "==" , this.leadstage)
}
return query;
}
)
.limit(5)
.snapshotChanges()
.subscribe(response => {
if(!response.length){
console.log("no data available");
return false;
}
...
错误:
类型“查询”缺少以下属性 键入“CollectionReference”:id、父级、路径、文档、 添加(2739)
类型上不存在属性“限制” 'AngularFirestoreCollection'.ts(2339)
【问题讨论】:
-
我的代码和那个不一样,有人在帮助我,请不要关闭问题
-
您可以编辑您的问题,在末尾添加 Edit 3,以解释为什么它不是重复的。详细一点,然后 ping @DougStevenson 说你已经更新了问题。
-
该线程中给出的答案是使用
get()方法,我已经实现了它,但我正在使用('leads' , ref => ref ....snapshotChanges()并且根据文档,事情不起作用,@frank 也在尝试帮帮我,但到现在还没有解决。
标签: angular typescript firebase google-cloud-firestore angularfire2