firebase事务处理程序应该能够处理空值,并且可以多次调用它。如果在具有空值的位置上调用它会发生什么。 (如果没有现有数据)是否有办法从继续承诺中了解它。下面的代码怎么样?
let isNull = false;
db.ref('/entry').transaction( currentValue => {
if(!currentValue) {
isNull = true;
// Do the updates
} else {
// Do the update
}
return currentValue;
}).then(() => {
console.log("IsNull", isNull);
})
答案 0 :(得分:0)
此示例用于检查特定用户ID是否在节点
下使用以下内容:
//Add this before OnCreate while declaring all variables
FirebaseUser firebaseUserId = FirebaseAuth.getInstance().getCurrentUser();
yourDatabaseSource.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
final String thisFirebaseUser = firebaseUserId.getUid();
if (dataSnapshot.hasChild(thisFirebaseUser)) {
//check your condition
} else {
//do something
}
}
希望这会有所帮助。