gpt4 book ai didi

firebase - Flutter:如何在Flutter中创建嵌套对象以存储在Cloud Firestore中

转载 作者:行者123 更新时间:2023-12-03 04:40:45 27 4
gpt4 key购买 nike

我正在寻找一种为Cloud Firestore中的市场构建类别和子类别的集合的方法,我想创建一个类别,并在每个类别内将每个类别与键值对映射,基本上是树结构。类似下面的内容
类别1 ----->数组
0 map
字段---->字符串----->值
字段----->字符串--->值
1张 map
字段---->字符串----->值
字段--->字符串--->值

var results = [
'Category 1' = [
{field: string , field: string, field: int}
{field: string , field: string, field: int}
{field: string , field: string, field: int}
'Category x'= [
{field: string , field: string, field: int}
{field: string , field: string, field: int}
]
]
];
这不是代码,这只是我要在Cloud Firestore中创建的结构的类型,我还附加了图像,因为如何在Cloud Firestore上进行结构化。
enter image description here

最佳答案

  var result = {
"result": {
"category1": [
{
"field1": "string",
"field2": "string",
"field3": 10
},
{
"field1": "string",
"field2": "string",
"field3": 10
},
{
"field1": "string",
"field2": "string",
"field3": 10
},
{
"category2": [
{
"field1": "string",
"field2": "string",
"field3": 10
},
{
"field1": "string",
"field2": "string",
"field3": 10
}
]
}
]
}
};


//save to firestore
Firestore.instance.collection(id).document().setData(result);
enter image description here

关于firebase - Flutter:如何在Flutter中创建嵌套对象以存储在Cloud Firestore中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63293466/

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