• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 React 게시판 현재 영수증 기능을 만들고 있는데 질문이 있습니다.

현재 영수증 기능을 만들고 있는데 질문이 있습니다.

4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 글쓴이
  • #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;

    #9073

    codingapple
    키 마스터

    <div className=”page”> 이거 통째로 반복문 돌리면 안됩니까

    #9077

    김창규
    참가자

    저도 반복문을 써봤지만 상품이 여러개일때 문제가 생깁니다 ㅠ 

    https://fefdfea.github.io/#/

    이 사이트가 반복문을 적용해서 만들었을때 입니다.

    #9080

    codingapple
    키 마스터

    그러게요 props로 장바구니 데이터를 잘 전해주고있는지 확인해봐야겠는데요

    잘 전해주고 있다면 css문제일 수도 있습니다 page라는 클래스명이 이상하거나 <receipt>를 담고있는 박스가 작을수도요

4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠