gpt4 book ai didi

typescript - Angular6 - JSON.stringify 无法序列化循环结构

转载 作者:搜寻专家 更新时间:2023-10-30 21:57:31 24 4
gpt4 key购买 nike

我总是收到类似标题此评论的错误。这是我的类 CreateChildComponent:

  @Input('father') father: Father = new Father();
child: Child = new Child();
submitted = false;
childList: Array<Child> = [];
family: Family = new Family();

constructor(private familyService: FamilyService) {
}

ngOnInit() {
}

createFamily() {
this.family.father = new Father();
this.family.father = this.father;
this.father.family = this.family;
this.family.childList = new Array<Child>();
this.family.childList = this.childList;
this.familyService.createFamily(cache).subscribe(data => console.log(data), error => console.log(error));
// this.familyService.createFamily(this.family)
// // .subscribe(data => console.log(data), error => console.log(error));
this.family = new Family();
}
addChildToList() {
this.child.family = this.family;
this.father.family = this.family;
this.childList.push(this.child);
}
}

我也试过解决这个问题,但不知道如何解决。我想将家庭对象发送到数据库。这是我使用 typescript 的第一步。谢谢你的帮助。

最佳答案

flat is better than nested

我们应该保持我们的状态normalized

const familyMap = {
1: new Family(),
2: new Family(),
};

const personsMap = {
1: new Father(),
2: new Child(),
};

createFamily() {
familyMap[1].father = {personId: 1};
personsMap[1].family = {familyId: 1};
}

关于typescript - Angular6 - JSON.stringify 无法序列化循环结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52220721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com