【发布时间】:2017-02-03 21:07:58
【问题描述】:
使用 AngularFire2 的 Angular 应用程序。我正在尝试在子对象上查询 firebase,而不仅仅是子字符串属性。按子字符串属性查询有效,但如何按整个对象查询。
此代码有效
// Given the following firebase data structure
httpCache: {
{ID}: {
url: 'www.fakeurl',
otherProperties: {}
}
}
// This code will return results if exists where the url matches
this.af.database.list('httpCache', {
query: {
orderByChild: 'url',
equalTo: 'www.fakeurl'
}
}).subscribe(x => {
if (x.length > 0) { console.log('match found!'); }
});
此代码不起作用:
// Given the following firebase data structure
httpCache: {
{ID}: {
request: {
url: 'www.fakeurl',
params: 'id=1'
},
otherProperties: {}
}
}
// This code throws an exception
let request = {
url: 'www.fakeurl',
params: 'id=1'
};
this.af.database.list('httpCache', {
query: {
orderByChild: 'request',
equalTo: request
}
}).subscribe(x => {
if (x.length > 0) { console.log('match found!'); }
});
这是一个例外:
Query: First argument passed to startAt(), endAt(), or equalTo() cannot be an object.
我正在尝试使用此处显示的第二种解决方案,其中过滤条件被推送到包含所有过滤器属性的子对象中: Query based on multiple where clauses in firebase
【问题讨论】:
-
下面快速戳。如果您共享 JSON 的 sn-p(作为文本,没有屏幕截图),我可以将代码与之匹配。但方法将如下所述。
标签: firebase firebase-realtime-database angularfire2