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

home2 게시판 React 게시판 개인 프로젝트 관련 질문드립니다

개인 프로젝트 관련 질문드립니다

  • 이 주제에는 1개 답변, 2명 참여가 있으며 codingapple3 년 전에 전에 마지막으로 업데이트했습니다.
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #39610

    송송송
    참가자
    미니 사이트를 직접 만들고 있습니다. json 파일을 직접 만들어서 그거를 불러와서 하고 있는데
    날짜 검색+키워드 포함한 검색에서 계속 오류가 나서 최대한 해보려했는데,, 감을 못잡아서 질문드립니다.
    
    날짜 선택하고, 키워드 입력
    --> 처음에는 잘 나오는데, 두 번째부터 다른 것들이 추가 됨
    
    날짜변경 코드들은 안 넣었을 때는 정상적으로 작동하다, 날짜변경 코드를 추가하니, 오류가 넘쳐나네요..
    
    const LostList = memo(() => {
      // 처음 날
      const [startDate, setStartDate] = useState();
      // 마지막 날
      const [endDate, setEndDate] = useState();
      // 날짜 변환
      const startTime = moment(startDate).format("YYYY.MM.DD");
      const endTime = moment(endDate).format("YYYY.MM.DD");
      let startDateArray = startTime.split(".");
      let endDateArray = endTime.split(".");
      // input ref
      const keywordInput = useRef();
      // 키워드
      let [openLost, setOpenLost] = useState(false);
      // 모달창 열기
      let [openLostModal, setOpenLostModal] = useState(false);
      // 리스트 만드는 상태값
      const [lostList, setLostList] = useState([]);
      // 리스트 개수 상태값
      const [count, setCount] = useState(0);
      const compareInt = (sd, ed, rd) => {
        if (sd <= rd && rd <= ed) {
          return 1;
        } else {
          return -1;
        }
      };
      // 날짜 비교하기
      const compareDate = (json) => {
        lostList == "" ? setCount(json.length) : setCount(openLost.length);
        json.map((v, i) => {
          {
            // json 데이터를 분리해서 담음
            let regDateArray = v.L_reg_date.split(".");
            let year = compareInt(
              startDateArray[0],
              endDateArray[0],
              regDateArray[0]
            );
            let month = compareInt(
              startDateArray[1],
              endDateArray[1],
              regDateArray[1]
            );
            let day = compareInt(
              startDateArray[2],
              endDateArray[2],
              regDateArray[2]
            );
            // 선택한 날짜 기간에 저장된 데이터가 포함되어 있으면, 배열에 추가
            if (year == 1 && month == 1 && day == 1) {
              newArray.push(v);
            }
          }
        });
      };
      useEffect(() => {
        (async () => {
          let json = null;
          try {
            const response = await axios.get(`http://localhost:3001/bbs_lost`);
            // json에 리스트 담기
            json = response.data;
            setLostList(json);
            compareDate(json);
          } catch (e) {
            console.log(e);
          }
        })();
      }, [openLost]);
      const onFilterKeyword = () => {
        const searchKeyword = keywordInput.current.value;
        // 리스트에서 input창에 입력된 값이 json에 있으면
        let newFilter = lostList.filter((value) => {
          return value.L_item.includes(searchKeyword);
        });
        // 검색어가 있다면
        if (searchKeyword) {
          compareDate(newFilter);
        }
        setOpenLost(newArray);
        // 중복으로 나오니 배열 초기화
        newArray = [];
        console.log("클릭");
      };
     
    
    
    		
    	
    #39617

    codingapple
    키 마스터
    오류하나부터 정해서 디버깅하면 됩니다 의심가는 부분부터 console.log 해봅시다
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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