ios - 如何使用本机反应在我的firestore上的文档上添加多个对象?
问题描述
我有我的收藏,在我的收藏上我有一个数组,在这个数组上我想添加一个多个对象。
使用我的方法,我只能添加一个对象,我想在我的数组上添加不同的对象
这是我的方法:
async function RegisterTeam () {
// User is signed in.
firestore()
.collection('Users')
.doc(await AsyncStorage.getItem ('userID'))
.update({
"MyTeam.newTeamObj":[{
Activity:activity,
City:city,
Adress:adress,
text: text,
members: members,
Owner:true
}]
})
.then(() => {
console.log('team created !')
})
}
这是我的模型:
解决方案
您想将更多对象添加到数组中,还是将不同对象添加到 newTeaObj 属性?
.update({ myTeam: firestore.FieldValue.ArrayUnion(data) })
或者
const prevData = [...myTeam]
.udapte({ myTeam: [...prevData, ...newObject]})
或者您可以使用子集合。
推荐阅读
- c# - 将字符串列表添加到字典,然后检索它的值
- javascript - 如何向用户输入添加文本 - Vue
- python - 在 scikit-learn 的 TfidfVectorizer 中传递非英文文本
- python - 使用容器隔离 dag 中的代码依赖关系 - 气流
- typescript - 如何让 skipLibCheck 只忽略依赖项中的 d.ts 而不是我们自己的 d.ts 文件?
- asp.net - 正则表达式验证字符串是否不包含特殊字符列表和允许的特殊字符后跟字母数字
- javascript - express:如何在使用 nginx 作为反向代理时获取客户端 IP 而不是 docker ip?
- c# - 手动创建 SignalR 集线器上下文
- magento2 - 安装 magento 2.3.5-p1 后,管理页面只显示加载光标
- java - 如何在 Android Studio 中发出 http post 请求?