๋ฐ์์จ ๋ฐ์ดํฐ๋ฅผ ๋ณด์ฌ์ฃผ๋ ์ด ๋ถ๋ถ ์ฝ๋๋ฅผ ์์ ํ๊ณ ์ถ์ด.
์ ๊ณตํ ์ํ๋ฐ์ดํฐ์ ๋ํด ์ด๋ค ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ฃผ๊ธธ ์ํ๋๋ฉด : ContainerList์์ ์ด 2๊ฐ์ ListContent ์์ฑ(์ด์ : recipe์ ingredient ๋ฐฐ์ด์ ๊ธธ์ด๊ฐ 2์ด๋๊น) : ๊ฐ ListContent ์๋ ์จ์ 100 200 335 ์ท 300 400 250 ์ด๋ ๊ฒ ๋ฐ์ดํฐ๊ฐ ๋ด๊ธฐ๊ธธ ์ํด
๋ค, ์ ๊ณตํด์ฃผ์ ๋ฐ์ดํฐ์ ์๊ตฌ์ฌํญ์ ๋ฐํ์ผ๋ก ์ฝ๋๋ฅผ ์์ฑํด๋ณด๊ฒ ์ต๋๋ค.
menuData.recipes ๋ฐฐ์ด์์ ๊ฐ recipe์ ingredient ๋ฐฐ์ด์ ์ํํ๋ฉฐ, ๊ฐ ์ฌ๋ฃ์ ๋ํ ์๋์ ๊ฐ ๋ฒํผ์ ํ์ํ๋ ๋ฐฉ์์ผ๋ก ์ฝ๋๋ฅผ ์์ฑํ์์ต๋๋ค.
{menuData &&
menuData.recipes &&
menuData.recipes[0].ingredient.map((ing, index) => (
<ListContent key={index}>
<img style={{ margin: "0 0 0 15px" }} src={Drag} />
<label style={{ marginLeft: "14px", fontFamily: "Pretendard", fontSize: '20px', width: "418px", height: "40px", background: "#FFFFFF", borderRadius: "8px", paddingLeft:'24px', paddingTop:'16px'}}>
{ing.ingredientName}
</label>
{menuData.recipes.map(recipe => {
const ingredient = recipe.ingredient.find(i => i.seq === ing.seq);
return (
<Button key={recipe.cupId}>
{ingredient ? ingredient.quantity : 'N/A'}
</Button>
);
})}
<img style={{ margin:"10" }} src={Del} />
</ListContent>
))}
์์ ์ฝ๋๋ ์๋์ ๊ฐ์ด ๋์ํฉ๋๋ค:
- ์ฒซ ๋ฒ์งธ ๋ ์ํผ(menuData.recipes[0])์ ๋ชจ๋ ์ฌ๋ฃ๋ฅผ ์ํํฉ๋๋ค.
- ๊ฐ ์ฌ๋ฃ์ ๋ํด ์๋ก์ด ListContent ์ปดํฌ๋ํธ๋ฅผ ์์ฑํฉ๋๋ค.
- ์ด ์ปดํฌ๋ํธ ๋ด๋ถ์์๋ ๋ชจ๋ ๋ ์ํผ๋ฅผ ๋ค์ ์ํํ์ฌ ํด๋น ์ฌ๋ฃ๊ฐ ํฌํจ๋ ๊ฒฝ์ฐ ๊ทธ ์๋์ ํ์ํ๊ณ , ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ 'N/A'๋ฅผ ํ์ํฉ๋๋ค.
์ด๋ ๊ฒ ์์ ๋ ์ฝ๋๋ก ์๋ํด๋ณด์๊ณ ์ํ๋ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์๋์ง ํ์ธํด์ฃผ์ธ์.