我想要在我的firebase数据库中的“服装”参考下获取所有firebase节点。要做到这一点,我附上ChildEventListener
到基准并在onChildAdded
回调我的Clothing
对象添加到衣服对象的列表,假设onChildAdded
回调被调用的次数也有在“衣”参考节点。为什么Firebase onChildAdded未被调用?
mClothingRef = FirebaseDatabase.getInstance()
.getReference()
.child("clothing");
final List<Clothing> clothingItems = new ArrayList<>();
mClothingRef.addChildEventListener(new ChildEventListener() {
public void onChildAdded(DataSnapshot snapshot, String s) {
Clothing clothing = snapshot.getValue(Clothing.class);
clothingItems.add(clothing);
Log.d(TAG, "onChildAdded called");
}
public void onCancelled(DatabaseError databaseError) {
Log.e(TAG, databaseError.getMessage() + " " +
databaseError.getCode() + " " + databaseError.getDetails() + " " + databaseError.toString());
mEventBus.post(new ListClothingFailEvent());
}
...
}
这里是数据库结构:
-->root
---->clothing
------>clothing_id
-------->title
-------->category
-------->img_download_url
------>clothing_id_1
-------->title
-------->...
我需要的服装节点下的所有节点。
我的数据库安全规则目前:
{
"rules": {
".read": "auth == null",
".write": "auth != null"
}
}
当被称为包含此代码的方法,该onChildAdded
回调不大,而不是onCancelled
回调是一个权限被拒绝的数据库错误。为什么会这样?
当我添加该行上会被忽略,因为该行没有被调用一个破发点。根据调试器的服装节点的参考url是:https://good-deal-9a0b2.firebaseio.com/clothing看起来正确 –
@TomFinet你能分享你的完整活动代码吗? – mark922
此代码不在活动中,但是它使用'mCatalogRepository.loadClothing()'从活动中调用。我会将其添加到问题中。 –