【发布时间】:2021-11-11 00:05:00
【问题描述】:
我在我的 ReactJS 页面上从 Rest API 调用接收 JSON(具有产品/类别相关信息)。我在 ag-grid 上呈现这些信息。
类别水平显示,并且针对每个类别,产品显示在列中。
---------|----- |----------|------------
Product1| Product2 | Product3
---------|-------------------------------
Category1|abc1 | abc2 | abc3
-----------------------------------------
Category2|xyz1 | xyz2 | xyz3
-----------------------------------------
JSON 可以包含任意数量的类别/产品。 我需要能够根据此信息动态呈现行/列。 不知道该怎么做?
产品数量最多为 5 个。 我是否应该在我的 reactJS 页面中定义这五个产品的标题定义,然后根据 JSON 中存在的产品动态地将 hidden 属性设置为 true 或 false?
[{
headerName: "Product1",
resizable: true,
wrapText: true,
cellStyle: {
'white-space': 'normal'
},
autoHeight: true,
hide: true
},
{
headerName: "Product2",
resizable: true,
wrapText: true,
cellStyle: {
'white-space': 'normal'
},
autoHeight: true,
hide: false
}]
JSON: 示例1:
"raw_message":
[
{
"category": "category1"
[
{
"product": "Product1"
},
{
"product": "Product2"
},
]
}
]
示例2:
"raw_message":
[
{
"category": "category1"
[
{
"product": "Product1"
},
{
"product": "Product2"
},
{
"product": "Product3"
},
]
}
]
【问题讨论】:
-
你能分享你的json格式的产品和货物相关信息吗?
-
嗨,Mahi,我添加了 json。谢谢。
-
你确定 json 格式是正确的,这是你得到的数据吗?