-
글쓴이글
-
2021년 5월 5일 14:58 #9064
김창규참가자안녕하세요 제가 영수증 기능을 만들다 막히는 부분이 생겼습니다. 밑의 코드에서 가장 아래 Receipt부분에 상품명, 가격 같은 곳에
props.cartlist에 대한 정보를 넣어야 하는데 어디서 반복문을 이용해야 할지 모르겠습니다... 아니면 저렇게 말고 다르게 할 방법이 있을까요?
import { Table,Button } from 'react-bootstrap';
import './css/cart.scss';
import React, { useEffect, useState } from 'react';function Cart (props){
let [state,state변경] = useState(false);return(
<div>
<Table striped bordered hover variant="dark" className="center">
<thead>
<tr>
<th>id</th>
<th>상품명</th>
<th>생산지</th>
<th>가격</th>
<th>수량</th>
<th></th>
<th>삭제</th>
</tr>
</thead>
<tbody>
{
props.cartlist.map((e,i) => {
return(
<Itme_list el={e} index={i} cartlist={ props.cartlist } cartlist변경={ props.cartlist변경 }/>
)
})
}
</tbody>
</Table>
{
state === true ? <Receipt cartlist={ props.cartlist }/> : null
}
<div className="order">
<Button variant="secondary" onClick={() => {
state변경(true);
}}>구매하기</Button>{''}
</div>
</div>
)
}function Itme_list(props){
return(
<>
<tr>
<td>{props.el.id}</td>
<td>{props.el.title}</td>
<td>{props.el.content}</td>
<td>{props.el.price}</td>
<td>{props.el.qua}</td>
<td>
<button onClick={() => {
let list = [...props.cartlist];
list[props.index].qua++;
props.cartlist변경(list);
}}>+</button>
<button onClick={() => {
let list = [...props.cartlist];
if(list[props.index].qua === 0){
return list;
}
else{
list[props.index].qua--;
}
props.cartlist변경(list);
}}>-</button>
</td>
<td>
<button onClick={() => {
let list = [...props.cartlist];
list.splice(props.index, 1);
props.cartlist변경(list);
}}>X</button>
</td>
</tr>
</>
)
}function Receipt(props){
return(
<>
<div className="page">
<p>상품명{ }</p>
<p>가격{}</p>
<p>수량{}</p>
<p>총 합계{}</p>
</div>
</>
)
}export default Cart;
2021년 5월 5일 18:12 #9077
김창규참가자저도 반복문을 써봤지만 상품이 여러개일때 문제가 생깁니다 ㅠ
https://fefdfea.github.io/#/
이 사이트가 반복문을 적용해서 만들었을때 입니다.
2021년 5월 5일 20:23 #9080
codingapple키 마스터그러게요 props로 장바구니 데이터를 잘 전해주고있는지 확인해봐야겠는데요
잘 전해주고 있다면 css문제일 수도 있습니다 page라는 클래스명이 이상하거나 <receipt>를 담고있는 박스가 작을수도요
-
글쓴이글
- 답변은 로그인 후 가능합니다.