Dart Firestore添加到数组 [英] Dart Firestore add to array

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

问题描述

我正在编写Flutter应用,并尝试向数组添加元素.我正在尝试按照以下示例进行操作:

那么,如何在该文档中向数组添加元素?

作为参考,我正在使用cloud_firestore:0.12.1依赖项.

解决方案

您应使用的方法是updateData().您将其传递给它.

这里是一个向数组(宽松命名为"arrayName")中添加元素(字符串"element")的示例:

  userPantry.updateData({'arrayName':FieldValue.arrayUnion(['element'])}) 

I'm writing a Flutter app and am trying to add an element to an array. I'm trying to follow the example here: https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array - however, My DocumentReference object does not have an update object:

So, how do I go about adding an element to an array in this document?

For reference, I'm using the cloud_firestore: 0.12.1 dependency.

解决方案

The method you should use is updateData(). You pass to it a map.

Here is an example adding an element (the string 'element') to an array (named loosely 'arrayName') :

userPantry.updateData({'arrayName': FieldValue.arrayUnion(['element'])})

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

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