Flutter:如何在 Flutter 中创建嵌套对象以存储在 Cloud Firestore 上
Flutter: How to create nested objects in Flutter to store on Cloud Firestore
我正在寻找一种方法来为 Cloud Firestore 中的市场构建类别和子类别的集合,我想创建一个类别并在每个类别中使用键值对映射每个类别,基本上是一个树结构.类似于下面的内容
类别 1 ----- > 数组
0张地图
字段 ----> 字符串 -----> 值
字段----->字符串-----> 值
1 张地图
字段 ----> 字符串 -----> 值
字段----->字符串-----> 值
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 上构建结构。
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);
我正在寻找一种方法来为 Cloud Firestore 中的市场构建类别和子类别的集合,我想创建一个类别并在每个类别中使用键值对映射每个类别,基本上是一个树结构.类似于下面的内容
类别 1 ----- > 数组
0张地图
字段 ----> 字符串 -----> 值
字段----->字符串-----> 值
1 张地图
字段 ----> 字符串 -----> 值
字段----->字符串-----> 值
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 上构建结构。
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);