如何从API React表中创建动态标头
如何根据API响应为我的React表创建标头?
例如,我不想为表手动定义列的数据,因此如何从对象的键中动态创建标题,
let testData = [
{
"id": "1",
"name": "test",
"namespace": "test",
"description": "test",
},
{
"id": "2",
"name": "test2",
"namespace": "test2",
"description": "test2",
} ]
请参见下面的答案
How can I create a header for my react table based on the API response?
for example the data I don't want to define columns manually for the table, so how can I create the headers dynamically from the keys of the object
let testData = [
{
"id": "1",
"name": "test",
"namespace": "test",
"description": "test",
},
{
"id": "2",
"name": "test2",
"namespace": "test2",
"description": "test2",
} ]
see answer below
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您想使表标头静态,因为您无法控制返回端点的内容。一种方法可能是:
您也可以应用相同的逻辑以避免手动插入身体。
Normally, you would like to make the table header static, because you can not control what's returning the endpoint. An approach to this might be this one:
You could also apply the same logic to avoid inserting the body manually.
我能够为此
//
提出
一个解决方案基于数据而不是手动定义标题。
I was able to come up with a solution for this
//so define the columns
//then pass in data and columns variable to table component
this is how you create dynamic headers based on data instead of manually defining headers.