firebase - 我想添加对象在firebase中具有对象列表,颤振
问题描述
我有对象“律师”有对象列表“制造商”
class Lawer{
final int x1;
final int x2;
final int x3;
final List<Maker>objects
Lawer({this.x1,this.x2,this.x3 ,this.objects});
Map<String, dynamic> toJson() =>
{
'x1':1 ,
'x2':1,
'x3':2,
};
}
class Maker{
final String lawerID;
final String customerID;
final bool connect;
Maker({this.lawerID,this.customerID,this.connect=false});
Map<String, dynamic> toJson() =>
{
'lawerID':lawerID,
'customerID':customerID,
'connect':connect,
};
}
CollectionReference dPReplies=FirebaseFirestore.instance.collection('lawers'); FirebaseFirestore.instance.runTransaction((Transaction tx)async {
var result=await dPReplies.add(lawer.toJson())
});
如何在firebase中保存这个对象“保存对象有一些变量和对象列表”
解决方案
在你的课堂上改变这个:
Map<String, dynamic> toJson() => { 'x1':x1, 'x2':x2, 'x3':x3, };
你需要大写
Lawer
var result= await dPReplies.add(Lawer.toJson()) //instead of lawer.toJson
推荐阅读
- c# - 使用 System.IO.File,检查文本文件是否包含确切的字符串而不是它的一部分
- java - 为什么 Java 函数能够返回本地数组?
- python - 使用 Pyinstaller 启动 Kivy 应用程序崩溃
- tensorflow - 如何使用具有可变长度特征和标签的 TF CTC 损失
- java - 如何从子类中获取 toString 方法的值到另一个类中,并通过 for 循环对其进行迭代以将值添加到一个字符串中?
- node.js - 这个oracle查询的芒果等价物是什么
- python - Pandas 以多列爆炸(不同的嵌套列表长度)
- asp.net-web-api - 使用 web api 发布文件时,我收到“消息:发生错误”但它不执行 catch
- ios - Firebase 动态链接在应用程序中打开我的所有域链接
- mysql - 当字符串是使用 MySQL 的表中另一列中的数据时,如何在表的一列中搜索字符串