【发布时间】:2022-01-10 08:36:36
【问题描述】:
我想从附件对象数组中删除附件,该附件对象数组位于另一个对象数组内的另一个注释对象数组内。我一直在努力解决这个问题。
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;
}
我的 ts 文件包含解决方案草案,但无法正常工作(不删除附件):
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),
);
}
}
【问题讨论】:
标签: angular typescript object