gpt4 book ai didi

firebase - 如何使用Flutter获取Firestore中的嵌套项目数

转载 作者:行者123 更新时间:2023-12-03 04:47:57 25 4
gpt4 key购买 nike

我又来自以下问题。

Add nested data in Firestore by flutter

我想提前知道这张 map 上有多少辆汽车。
在这种情况下,我需要在汽车标签上编号才能更新(添加)。

'cars': {
'car1': {
'name': name,
'img_url': 'https://www.xxx.xxx/xxx.png',
'details': {
'type': carType,
}
},
'car2': {
'name': name,
'img_url': 'https://www.xxx.xxx/xxx.png',
'details': {
'type': carType,
}
}
}

在这种情况下,我要2。
还是更好的方法?请给我建议。

最佳答案

您需要检索cars映射:

_firestore.collection('members').document(${loginUser.uid}).get().then((value){
print(value.data);
Map<String,dynamic> cars = value.data["cars"];
print(cars.length);
});

检索文档,然后使用 length属性获取 cars映射内的元素数。

关于firebase - 如何使用Flutter获取Firestore中的嵌套项目数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61931803/

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