Hi Im starting with the reactjs. After working with the basics in react, Im trying to work on the reactjs with dynamoDB. First query Im working on is Select query, and render the table in html file. So right now Im able to get the json array from desired table using select query. But Im not able display the rendered data in a table format i.e I get a json array like below and able to display data 4281, taniv, secondary... but not able to display the header for each value (id, name, class, etc.), so how to display the header for each json value. I want it to be dynamic because I want to show what is in the db(if some of the attributes are not there or missing I don't want it to be displayed) :
[
{
"id": 4281,
"name": "taniv",
"class": "secondary",
"admission": 227,
"telephone": "209-109-2322",
"address": "11 first lane",
"postCode": "5788009",
"county": "UK",
}]
js
Result
{data.map((obj, y) => {
return Object.keys(obj).map((x, y) =>
{obj[x]} )})}
解决方案
I made an example on codesandbox.io for you (:
From what I understood you are trying to make your table completely dynamic. You essentially want keys in your object to be table headers and corresponding values to be table row data. Please checkout the example and let me know if this helps or if you have any questions you can find me on Twitter (@jonmajorc). Good luck!