Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 如何更改Firestore中文档数组字段的某个索引的值?_Firebase_Google Cloud Firestore_Angularfire - Fatal编程技术网

Firebase 如何更改Firestore中文档数组字段的某个索引的值?

Firebase 如何更改Firestore中文档数组字段的某个索引的值?,firebase,google-cloud-firestore,angularfire,Firebase,Google Cloud Firestore,Angularfire,我有一个带cloud firestore的angular应用程序,其结构如下: --nombre --grupo --nombre1 --nombre2 --nombre3 --numerocuenta1 --numerocuenta2 --numerocuenta3 --resuelto --0: false --1: false . . . --13: false 如您所见,最后我有一个包含13个元素的布尔数组(resuelto),我想在单击具有相同索引的元素时更改

我有一个带cloud firestore的angular应用程序,其结构如下:

--nombre
--grupo
--nombre1
--nombre2
--nombre3
--numerocuenta1
--numerocuenta2
--numerocuenta3
--resuelto
  --0: false
  --1: false
  .
  .
  .
  --13: false
如您所见,最后我有一个包含13个元素的布尔数组(resuelto),我想在单击具有相同索引的元素时更改某个索引的值

有没有办法访问该数组的每个索引并更改其值

我试过这个:

this.taskDoc = this.afs.doc(`tasks/${task`);
this.taskDoc.update(resuelto[0]); <-- 
this.taskDoc=this.afs.doc(`tasks/${task`);

this.taskDoc.update(resuelto[0]);Firestore不支持单个数组元素的更新。如果您有一个数组,并且希望更改其中一个值,则必须读取整个数组,在本地更改该值,然后将整个数组写回


您最好将数据建模为对象而不是数组。可以通过调用对象字段来单独更新对象属性。

Firestore不支持单独数组元素的更新。如果您有一个数组,并且希望更改其中一个值,则必须读取整个数组,更改值locally,然后将整个数组写回


您最好将数据建模为对象而不是数组。可以通过调用对象字段来单独更新对象属性。

虽然您不能按索引对数组中的某些元素执行操作,但可以使用ArrayOnion和arrayRemove按值在数组中添加或删除元素:

doc.update("someField" : FieldValue.arrayUnion("someValue"))
doc.update("someField" : FieldValue.arrayRemove("someValue"))

这使数组的行为更像一个集合,而不是一个数组,但它至少为您提供了一些选项。此处的更多文档:

虽然您不能按索引对数组中的某些元素执行操作,但您可以使用ArrayOnion和arrayRemove按值在数组中添加或删除元素:

doc.update("someField" : FieldValue.arrayUnion("someValue"))
doc.update("someField" : FieldValue.arrayRemove("someValue"))

这使得数组的行为更像一个集合,而不是一个数组,但它至少为您提供了一些选项。此处有更多文档:

resuelto是文档中实际的数组类型字段?抱歉,我不太明白,您的意思是什么?在Firebase控制台中查看文档。如果您愿意,请截图并张贴在此处。它是否说d是数组类型?是的,它是一个数组resuelto是文档中实际的数组类型字段?对不起,我不太明白,你的意思是什么?在Firebase控制台中查看文档。如果需要,截图并发布在这里。它是否说字段是数组类型?是的,它是数组