Hello! I was re-factoring a shopping mall-like homepage made of the existing express and ejs code with React, but something was strangely blocked, so I'm posting. Come to think of it, it's very basic, but I'm not a developer. ㅜㅜ I'm looking for help just in case.
Somehow, the data received from the cookie was converted through JSON.parse, as shown below Data received.
{
"5ddf94251c37ea40c8f01b0a": {
"name": "Black Bean Noodles",
"native": "Member",
"divide": "Dinner menu",
"price": 10000,
"unit": "Number",
"count": "22",
"amount": 220000
},
"5de1ad2e92bed640dcda28a1": {
"name": "Jjamppong",
"native": "Assistant Member",
"divide": "Dinner menu",
"price": 12000,
"unit": "Number",
"count": "12",
"amount": 144000
}
}
I tried to code it as below to render this data, but now that I think about it, it's not an array. I don't know what to do.
const Cart = () => {
return (
<table>
<tbody>
{list && list.map(l => (
<tr>
<td>{l.name}</td>
<td>{l.native}</td>
<td>{l.divide}</td>
<td>{l.price}</td>
<td>{l.unit}</td>
<td>{l.count}</td>
<td>{l.amount}</td>
</tr>
)}
</tbody>
</table>
);
};
Of course, I gave out an error called map is not function, but my head suddenly became blank
I tried googling to see if I should arrange the JSON and turn it into a map, but I couldn't find an example using JSON in that way.
Is there a good plan?
react node.js json
JS object of objects to array I googled one, but the case looks a little similar.
https://medium.com/chrisburgin/javascript-converting-an-object-to-an-array-94b030a1604c
I hope it's useful.
© 2024 OneMinuteCode. All rights reserved.