gpt4 book ai didi

firebase - 如何更新已全部插入列表的Map中的嵌套列表?例如。 List < map <字符串,动态>>

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

我正在尝试更新或添加到 map 中列表的末尾,并将所有列表插入包含这些 map 的列表中。列表名称是“类”,我尝试使用的是点符号,所以使用classes.index.example,但这是行不通的。为什么...假设我在列表中有两个索引,如果我继续更新索引0,则会在正确的索引中插入“问题”和“答案”,但是由于某种原因,它将删除索引1和任何其他已创建的。好像它正在覆盖所有数据,但是我不明白为什么,我没有使用'setData()'。此外,如果我省略了'title',那也会被删除?

 Future updattingUserData(int index, List<dynamic> question, List<dynamic> answer, String title) async {
return await _collref.document(uid).updateData({
"classes.$index.questions": FieldValue.arrayUnion(question),
"classes.$index.answers": FieldValue.arrayUnion(answer),
//"classes.$index.title": title
});
}

最佳答案

Firestore无法更改仅在数组字段中知道其索引的数组元素。您需要做的是阅读文档,修改内存中的classes数组,然后将整个classes数组字段更新回文档。

关于firebase - 如何更新已全部插入列表的Map中的嵌套列表?例如。 List < map <字符串,动态>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61215366/

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