我试图在 equalTo()
方法中使用“OR”||
语句,但这似乎不起作用。我是否必须为每个值单独调用,或者有没有办法在 firebase 中进行条件查询?
export const startSetContent = () => {
return (dispatch, getState) => {
const ref = database.ref("content");
return ref
.orderByChild("category")
.equalTo('one-act-play' || 'ten-min-play' || 'full-length-play')
.once('value')
.then(snapshot => {
const content = [];
snapshot.forEach(childSnapshot => {
content.push({
id: childSnapshot.key,
...childSnapshot.val()
});
});
dispatch(setContent(content));
});
};
};
最佳答案
你在那里输入的是一个逻辑或,JavaScript 编程语言会解释它。表达式的结果:
'one-act-play' || 'ten-min-play' || 'full-length-play'
将是简单的:
'one-act-play'
因此,Firebase 实时数据库不会看到您试图告诉它的内容。
Firebase 实时数据库没有包含 OR 的查询的概念。您必须分别查询每种类型的事物,然后根据需要将它们合并到您的代码中。
关于javascript - 如何在 firebase 中查询给定键的多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48234955/