附加到Firestore中的Arary字段 [英] Append to an arary field in Firestore

查看:65
本文介绍了附加到Firestore中的Arary字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase和Vuejs创建一个数据库元素,其中包含对象数组.

I'm using Firebase and Vuejs to create an database element, which has object array inside.

这就是对象的外观,我想通过表单将任务添加到"moreTasks"选项卡中.

That's how the object looks, and I want to add tasks through the form into the 'moreTasks' tab.

我尝试使用它,但是它只是在数据库中创建新实体.

I tried using this, but it just creates new entity in the database.

      db.collection('Tasks').add({
    tasker: this.tasker.taskerName
  })

我也尝试检查API,但我无法理解引用,因为我使用了不同的方法来实现该目标.

I also tried checking API but I couldnt understand the refs, because I was using different methods to achieve that goal.

creatTask() {
  db.collection('Tasks').add({
    task_id: this.task_id,
    name: this.name,

...

解决此问题的正确方法是什么?

What would be correct way to approach this problem?

推荐答案

您可以使用

You can append an item to an array using FieldValue.arrayUnion() as described in the documentation. For example:

// Atomically add a new region to the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
});

这篇关于附加到Firestore中的Arary字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆