使用AngularFire2的角度应用程序。我试图在子对象上查询firebase,而不仅仅是一个子字符串属性。查询由子字符串属性工作,但我怎么能通过整个对象查询。通过子对象查询AngularFire2
此代码的工作
// 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片段(作为文本,没有截图),我可以匹配的代码。但是,这种方法将如我在下面描述的那样。 –