In my project i want to make a model contains nested data based on mutiple api calls.(i mean after calling api based on ids calling another api on click);
- First API call.
[
{
id: 1,
name: "user 1"
},
{
id: 1,
name: "user 2"
}
]
- By using these parent ids i am calling another api for the childrens. for example id = 1
[
{
id: 3,
name: "child 1",
parentId: 1
},
{
id: 3,
name: "child 2",
parentId: 1
}
]
- Again using these child ids calling another api for sub childs.
[
{
id: 5,
name: "baby 1",
parentId: 3
},
{
id: 5,
name: "baby 2",
parentId: 3
}
]
and this is further.... calling..
so finally the final data like this
[
{
id: 1,
name: "user 1",
children: [
{
id: 3,
name: "child 1",
parentId: 1,
children: [
{
id: 5,
name: "baby 1",
parentId: 3,
children: // further
},
{
id: 5,
name: "baby 2",
parentId: 3,
children: // further
}
]
},
{
id: 3,
name: "child 2",
parentId: 1,
children: // same structure
}
]
},
{
id: 1,
name: "user 2",
// same structure
}
]
export interface IUser {
id?: any;
name?: string;
children?: // here what i need to do
parentId?: any;
active: boolean;
}
export class User implements IUser {
public id?: any;
public name?: string;
public children?: // here what i need to do
public parentId?: any;
public active = false;
constructor(data: IUser) {
Object.assign(this, data);
}
}