如何将动态数据映射到角度材料表中的相应标题?我有按类别过滤数据的情况(在 parcelItems 下总是会有 2 个类别但未排序),如下所示。在这种情况下, Wears and Accessories是标题。Api 响应未在后端排序。我怎样才能做到这一点?
这是代码:stackblitz
样本
|---------------------|------------------------------|
| Heading 1 (Wears) | Heading 2 (Accessories) |
|---------------------|------------------------------|
| jeans | earphones |
|---------------------|------------------------------|
| t-shirt | motherboard |
|---------------------|------------------------------|
示例.json
const ELEMENT_DATA: Array<Data> = [
{
fname: "Mark",
lname: "jhony",
parcels: [
{
parcelId: 123,
parcelName: "parcel1",
parcelItems: [
{
name: "jeans",
category: "wears",
qty: 2
},
{
name: "earphones",
category: "accessories",
qty: 4
},
]
},
{
parcelId: 144,
parcelName: "parcel2",
parcelItems: [
{
name: "motherboard",
category: "accessories",
qty: 5
},
{
name: "t-shirt",
category: "wears",
qty: 7
},
]
}
]
}
];