Roc*_*kal 2 javascript firebase google-cloud-firestore
我正在使用Firebase和Vuejs创建一个数据库元素,其中包含对象数组。
这就是该字段的外观,我想通过表单将任务作为数组添加到“moreTasks”中。
我尝试使用它,但它只是在数据库中创建新实体。
db.collection('Tasks').add({
tasker: this.tasker.taskerName
})
Run Code Online (Sandbox Code Playgroud)
我也尝试检查 API,但我无法理解参考文献,因为我使用不同的方法来实现该目标。
creatTask() {
db.collection('Tasks').add({
task_id: this.task_id,
name: this.name,
Run Code Online (Sandbox Code Playgroud)
解决这个问题的正确方法是什么?
您可以使用FieldValue.arrayUnion()将项目附加到数组,如文档中所述。例如:
// Atomically add a new region to the "regions" array field.
washingtonRef.update({
regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5098 次 |
| 最近记录: |