【发布时间】:2019-12-31 02:03:30
【问题描述】:
我在 abc 集合中有 xyz 文档。
- 我想将 map 添加到 document xyz 内的 an array。
我可以使用此代码添加单个数组项
CollectionReference collection = this.collection(collection);
DocumentReference ref = collection.document(document);
ref.setData({"data": FieldValue.arrayUnion(values)});
这里的data是父数组。
但是当我尝试添加另一个 map 时,firestore 替换索引 0 的值,它 不会将地图添加到下一个索引 表示索引 1,2,3 或.....
让我们看看例子 这是地图
values = {
"tokens": "99",
"title": "Cleaning",
"location": {" lat": "34.4333", "lng": "53.4343"},
"id": "gVnGE5ZPRnQ8HYQq7dvT",
"client": "LFBXXj7Zi0xOr0FqBGID",
"date": "22/8/2019",
"message": "request message...",
"budget": "150",
"details": {
" When would you like to have the cleaners over?":
"week",
"What type of cleaning package would you prefer?":
"answer for the type of clean",
"Do you need the cleaning tools and materials?":
"false",
"What time do you prefer to have the cleaners over?":
"8/20/2019"
}
}
我想在每次将数据发送到 Firestore 时将其添加为新的数组项
例如。
onTap() {
CollectionReference collection = this.collection(collection);
DocumentReference ref = collection.document(document);
ref.setData({"value": FieldValue.arrayUnion(values)});
}
这里是代码
var values = {
"tokens": "99",
"title": "Cleaning",
"location": {" lat": "34.4333", "lng": "53.4343"},
"id": "gVnGE5ZPRnQ8HYQq7dvT",
"client": "LFBXXj7Zi0xOr0FqBGID",
"date": "22/8/2019",
"message": "request message...",
"budget": "150",
"details": {
" When would you like to have the cleaners over?":
"week",
"What type of cleaning package would you prefer?":
"answer for the type of clean",
"Do you need the cleaning tools and materials?":
"false",
"What time do you prefer to have the cleaners over?":
"8/20/2019"
}
}
onTap() {
CollectionReference collection = this.collection(collection);
DocumentReference ref = collection.document(document);
ref.setData({"value": FieldValue.arrayUnion(values)});
}
【问题讨论】:
标签: arrays firebase flutter google-cloud-firestore maps