You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何基于JSON数据在Angular Material Table中动态生成列(含固定列)

Angular Material Table动态列生成问题

已在Angular Material Table中设置start Date、End Date两个固定列,需要根据服务器返回的响应生成动态表格——后端返回的details数组大小不固定,有时包含2列,有时包含3列甚至更多。尝试过多个Angular Material动态列示例,但均未成功。

当前JSON响应示例

{
    "cars": [
        {
            "startDate": "01/11/2020",
            "endDate": "03/03/2021",
            "details": [
                {
                    "nameofThecar": "Dodge",
                    "color": "Silver",
                    "type": "Sedan"
                },
                {
                    "nameofThecar": "Nissan",
                    "color": "White",
                    "type": "micro"
                },
                {
                    "nameofThecar": "Kia",
                    "color": "blue",
                    "type": "supercar"
                }
            ]
        },
        {
            "startDate": "05/01/2020",
            "endDate": "12/05/2021",
            "details": [
                {
                    "nameofThecar": "Dodge",
                    "color": "gold",
                    "type": "SUV"
                },
                {
                    "nameofThecar": "Nissan",
                    "color": "blue",
                    "type": "MPV"
                },
                {
                    "nameofThecar": "Kia",
                    "color": "silver",
                    "type": "wagon"
                }
            ]
        }
    ]
}

预期表格样式

预期表格样式

内容的提问来源于stack exchange,提问作者learntech

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 02:17:14