admin管理员组文章数量:1023089
I am using Google's Firestore for searching a database, and the logic is to name your source, then chain where() methods for each variable. An example of working code is:
var ref = firebase.firestore().collection('myCol');
ref.where('myVar1','==',true).where('myVar2','==',5).get()
.then((results) => {...})
The problem I'm having is I have no idea how to dynamically attach those where() methods (as the number of them will change with each different search). I suspect if I knew the name of it I'd be able to find it, but dot functions didn't show up much... How could I do this?
I am using Google's Firestore for searching a database, and the logic is to name your source, then chain where() methods for each variable. An example of working code is:
var ref = firebase.firestore().collection('myCol');
ref.where('myVar1','==',true).where('myVar2','==',5).get()
.then((results) => {...})
The problem I'm having is I have no idea how to dynamically attach those where() methods (as the number of them will change with each different search). I suspect if I knew the name of it I'd be able to find it, but dot functions didn't show up much... How could I do this?
Share Improve this question edited Oct 27, 2017 at 20:18 xon52 asked Oct 26, 2017 at 10:00 xon52xon52 7365 silver badges13 bronze badges 3- What are "dot functions"? – Tomalak Commented Oct 26, 2017 at 10:04
-
3
Chaining is often just a case where the method returns itself, or another object. So just a keep a reference to this.. eg..
var last = ref.where(..);
, thenlast = last.where(..)
etc. – Keith Commented Oct 26, 2017 at 10:04 - 6 Please don't use the question to provide an answer to it. Instead write your answer below. You can accept it in 2 days as well. If you are looking for an answer, the question is definitely not the first place you are looking for it ;) – geisterfurz007 Commented Oct 26, 2017 at 11:56
1 Answer
Reset to default 6From @Keith's reply below, I got it working using:
var vars = ['myVar1', 'myVar2', 'myVar3'];
var ref = firebase.firestore().collection('myCol');
vars.forEach(v => { ref = ref.where(v, '==', true) });
ref.get()
.then(results => { ... })
.catch(err => { ... })
I am using Google's Firestore for searching a database, and the logic is to name your source, then chain where() methods for each variable. An example of working code is:
var ref = firebase.firestore().collection('myCol');
ref.where('myVar1','==',true).where('myVar2','==',5).get()
.then((results) => {...})
The problem I'm having is I have no idea how to dynamically attach those where() methods (as the number of them will change with each different search). I suspect if I knew the name of it I'd be able to find it, but dot functions didn't show up much... How could I do this?
I am using Google's Firestore for searching a database, and the logic is to name your source, then chain where() methods for each variable. An example of working code is:
var ref = firebase.firestore().collection('myCol');
ref.where('myVar1','==',true).where('myVar2','==',5).get()
.then((results) => {...})
The problem I'm having is I have no idea how to dynamically attach those where() methods (as the number of them will change with each different search). I suspect if I knew the name of it I'd be able to find it, but dot functions didn't show up much... How could I do this?
Share Improve this question edited Oct 27, 2017 at 20:18 xon52 asked Oct 26, 2017 at 10:00 xon52xon52 7365 silver badges13 bronze badges 3- What are "dot functions"? – Tomalak Commented Oct 26, 2017 at 10:04
-
3
Chaining is often just a case where the method returns itself, or another object. So just a keep a reference to this.. eg..
var last = ref.where(..);
, thenlast = last.where(..)
etc. – Keith Commented Oct 26, 2017 at 10:04 - 6 Please don't use the question to provide an answer to it. Instead write your answer below. You can accept it in 2 days as well. If you are looking for an answer, the question is definitely not the first place you are looking for it ;) – geisterfurz007 Commented Oct 26, 2017 at 11:56
1 Answer
Reset to default 6From @Keith's reply below, I got it working using:
var vars = ['myVar1', 'myVar2', 'myVar3'];
var ref = firebase.firestore().collection('myCol');
vars.forEach(v => { ref = ref.where(v, '==', true) });
ref.get()
.then(results => { ... })
.catch(err => { ... })
本文标签: Dynamically chain methods to javascript functionStack Overflow
版权声明:本文标题:Dynamically chain methods to javascript function - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745507228a2153660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论