【发布时间】:2021-08-20 22:13:00
【问题描述】:
以下代码直到今天都可以正常工作。但我现在不知道它不起作用并给出以下错误。你能告诉我为什么吗?
错误:使用无效数据调用函数 DocumentReference.set()。 不支持的字段值:自定义预算对象
export class Project {
id: string = null;
name: string;
budgetList?: Budget[];
}
export class Budget {
id: string;
amount: number;
contingency: number = 20;
budgetGroup: BudgetGroup = new BudgetGroup();
creationTime: string;
}
代码:
async create(data: DtoProject): Promise<Project> {
try {
const projectId: string = this.fireStore.createId();
const budgets = this.budgetProvider.createBudgets(data.budgetList, projectId);//budgets
const proj: Project = {
id: data.id,
name: data.name,
budgetList: budgets,//here it has the error
}
proj.id = projectId;
await this.fireStore.doc<Project>(`projects/${projectId}/`).set(proj));//project
}
}
createBudgets(data: Budget[], projectId: string): Budget[] {
let budgets: Budget[] = [];
forEach(data, (d) => {
const budgetId: string = this.fireStore.createId();
d.id = budgetId;
budgets.push(d);
this.fireStore.doc<Budget>(`projects/${projectId}/budgets/${budgetId}`).set({
id: budgetId,
amount: d.amount,
contingency: d.contingency,
budgetGroup: d.budgetGroup,
creationTime: moment().format()
})
})
return budgets;
}
【问题讨论】:
-
我在传入一些字段值意外为空的 json 对象时遇到了这个错误
标签: angular typescript firebase ionic3 google-cloud-firestore