如何解决如何从 firebase 中检索值一对多关系?
"item03" : {
"description" : "...... ","image_url" : "....","name" : ".....","price" : "250.00"
}
item = FirebaseDatabase.getInstance().getReference("Category")
.child(categoryID).child("Items");
private void fetchData() {
FirebaseRecyclerOptions<ItemModel> options = new FirebaseRecyclerOptions.Builder<ItemModel>()
.setQuery(item,new SnapshotParser<ItemModel>() {
@NonNull
@Override
public ItemModel parseSnapshot(@NonNull DataSnapshot snapshot) {
return new ItemModel(snapshot.child("name").getValue().toString(),snapshot.child("description").getValue().toString(),snapshot.child("image_url").getValue().toString(),snapshot.child("price").getValue().toString());
}
}).build();
// Set the adapter
itemsAdapter = new ItemsRecyclerViewAdapter(options);
}
我无法访问 name、imageurl 和其他属性,因为 snapshot.getvalue 返回 true 如何从具有一对多关系的 firebase 中检索值?
解决方法
您正在尝试从 name
节点读取 description
、"item01": true
和其他属性。这是行不通的,因为该节点上不存在这些属性。
您需要加载该特定项目的快照,然后从那个读取属性。这相当重要,因此我强烈建议使用专为此案例制作的 setIndexedQuery
method。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。