我试图从Firebase查询中返回一个布尔值,但似乎无法弄清楚。这是代码:
const checkUser = (user) => database.ref('myDatabase')
.orderByChild('userName')
.equalTo(user)
.on('child_added', (snapshot) => {
return snapshot.key ? TRUE : FALSE
});
const verifyUser = (u) => {
if (checkUser(u) === TRUE) {
return 'Username exists!'
} else {
return 'Username does not exist!'
}
}
console.log(verifyUser('john69'));
我还想知道此功能是否有简写形式。谢谢!