gpt4 book ai didi

firebase - 在不知道某些子名称的情况下从 Firebase 数据库获取所有值

转载 作者:IT王子 更新时间:2023-10-29 07:01:00 24 4
gpt4 key购买 nike

我试图在不知道父子 keys 的情况下获取一些子 values,因为它们是由用户或 firebase 生成的 UUID。

我的 firebase 结构是这样的:

{
AllUsers: {

76f4bd92-1fcd-4b4d-86c5-66b7e2822def: { // uuid generated by user

Users Username: {

-LCdF2QJ5c46lRnndtmY: { // uuid generated by firebase
count: 1,
dateTime: 1526479204163,
name: "picture1",
url: "https://firebasestorage.googleapis.com/",
},
-LCdF2QJ5c46lRnndtmQ: {
count: 2,
dateTime: 1526479204163,
name: "picture2",
url: "https://firebasestorage.googleapis.com/",
}
}
}
}
}

我正在尝试让所有用户生成 uuidusernames,以及按 排序时他们第一张图片的 url >count,这样我就可以将它们保存到这样的结构中:

class GalleryFolderView {
String uuid;
String name;
String firstImageUrl;

GalleryFolderView(this.uuid, this.name, this.firstImageUrl);
}

我的代码已经走到这一步,但无法深入结构:

  reference = FirebaseDatabase.instance.reference().child("AllUsers");
reference.onValue.listen((Event event) {
var key = event.snapshot.value.keys.toString();
print(key); => // prints out (76f4bd92-1fcd-4b4d-86c5-66b7e2822def) why the brackets?
});

如有任何帮助,我们将不胜感激。

最佳答案

这应该做你想做的:

 reference.onValue.listen((Event event) {
var value = event.snapshot.value;
var uuids = value.keys;
for(var uuid in uuids) {
var userNames = value[uuid].keys;
for(var userName in userNames) {
var images = value[uuid][userName].values;
var image = images.firstWhere((img) => img[count]== 1);
print('uuid: $uuid, userName: $userName, url: $image);
}
}
});

关于firebase - 在不知道某些子名称的情况下从 Firebase 数据库获取所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50375199/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com