I am currently grappling with the challenge of removing an attachment from an array of attachments within a nested structure of comment objects. Despite several attempts, I have yet to find a solution that works effectively.
export class CommentSection{
id: string;
comments: CommentObject[];
}
export class CommentObject{
id: string;
created: Date;
text: string;
attachments: CommentAttachment[];
}
export class CommentAttachment{
id: string;
created: Date;
filename: string;
}
In my TypeScript file, I have included a draft solution which unfortunately is not functioning as expected:
export class CommentsComponent {
public comment: CommentObject;
commentsArray: CommentSection;
public deleteCommentAttachment(attachment: CommentAttachment): void {
this.commentsArray.comments = this.commentsArray.comments.filter((c) =>
c[this.comment.id].attachments.splice(attachment.id, 1),
);
}
}