本文介绍了flutter firestore,在数组中添加新对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有对象数组,我想在用户在数组中输入新数据时添加新对象?
I have array of objects, I want to add new object when user enter new data in the array?
Firestore.instance.collection(city).document('Attractions').updateData(
"data", FieldValue.arrayUnion(obj)
);
这显示错误,我如何使用颤振来实现这一点?
This shows error, How can I achieve this with flutter?
推荐答案
正确的格式是:
Firestore.instance.collection(city).document('Attractions').updateData({"data": FieldValue.arrayUnion(obj)});
updateData
取Map
作为数据.
在您的代码中,您将 ,
作为键 - 值之间的分隔符,而应该是 :
In your Code you are having ,
as separator between key - value instead it should be :
这篇关于flutter firestore,在数组中添加新对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!