【发布时间】:2020-03-26 03:41:14
【问题描述】:
如何根据索引更新列表中的特定值?例如,在以下列表中:
0 [
{
first_name: name0,
last_name: lastName0,
}
]
1 [
{
first_name: name1,
last_name: lastName1,
}
]
如何只更新“lastName1”?目前,我正在使用一个使用 ArrayUnion 的 hacky 解决方案,它使用数据比较而不是实际索引(我将值加载到表单中,删除原始值然后重新添加):
// Retrieve data at index, load into form
// Remove that index from List
await Firestore.instance.collection(col).document(doc).updateData({
'people': FieldValue.arrayRemove([person])
});
// Make changes to data via form
// Save back to list
await Firestore.instance.collection(col).document(doc).updateData({
'people': FieldValue.arrayUnion([person])
});
是否有一个函数可以让我指定要更新哪个特定索引的数据?类似的东西(但使用列表,而不是地图):
await Firestore.instance.collection(col).document(doc).updateData({
'people.$index.lastName1': 'newName')
});
【问题讨论】:
标签: flutter google-cloud-firestore