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

home2 게시판 React 게시판 value값 가져오기 관련 질문

value값 가져오기 관련 질문

4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 글쓴이
  • #56783

    배희창
    참가자
    오랜만에 인사드립니다 선생님.
    
    eval 머시기까지 해서 만들어보다 답이 안나와서 질문 드립니다.
    
    input 값을 가져와서 서버로 보내야하는데, 문제가 무엇이나면
    
    
    
    저기 텍스트에 입력한 값을 추출해서 ajax로 보내면 되는데, 그 추출하는거는
    여태까지 다른 곳에서 추출은
    
    let [a, setA] = useState();
    let handle = (e) => {
        setA(e.target.value);
    }
    이걸 바뀌는 부분에 onChange로 달아줘서 해결했는데
    
    위에 인풋의 문제가 map문으로 카테고리 개수만큼 저 인풋을 생성해서
    
    ohchange로 만드는 함수도 저 인풋 개수만큼이 필요한 상황입니다.
    
    함수를 for문으로 만드는 방법이 있나요..? 구글에선 명쾌한 답이 없습니다..
    
    아니면 혹시 다른 쉬운 길이 있을까요? jquery를 써서 id값을 반복으로 달아서 가져와야하나요..
    
    한줄 요악은 반복문으로 생성된 input들의 value를 한꺼번에 가져오는 법입니다 ㅠㅠ
    
    
    #56803

    codingapple
    키 마스터
    array나 object state 하나 만들고
    input에 뭐 입력하면 그 state에 값을 추가하라고 코드짜놓읍시다 
    어려우면 함수부터 만들 생각하지말고 onChange={}에 하드코딩부터 하면 됩니다
    #56824

    배희창
    참가자
    감사합니다 선생님! 그럼 node 관련 질문 하나만 더 여쭤보겠습니다.
    
    카테고리 삭제시 -> 해당 카테고리 파일 삭제 및 카테고리 게시물 삭제 -> 카테고리 삭제
    
    코드를 짜놨는데, 문제점이
    
    a 카테고리 만들고 1 게시물 올려서
    카테고리 삭제하면 순차적으로 정상작동합니다. 근데 연이어서
    
    b 카테고리 만들고 2 게시물 올려서 삭제하면
    fs인지 db인지 1 게시물의 src값을 찾아와서 삭제하려고합니다.
    
    node:internal/fs/utils:345
        throw err;
        ^
    Error: ENOENT: no such file or directory, unlink './public/image/1670206975768E_NICE_0.jpg'
        at Object.unlinkSync (node:fs:1735:3)
        at C:\Users\user\Desktop\Leobinus\server.js:339:12
        at C:\Users\user\Desktop\Leobinus\node_modules\mongodb\lib\utils.js:371:9
        at C:\Users\user\Desktop\Leobinus\node_modules\mongodb\lib\cursor\abstract_cursor.js:260:32
        at C:\Users\user\Desktop\Leobinus\node_modules\mongodb\lib\cursor\abstract_cursor.js:510:55
        at C:\Users\user\Desktop\Leobinus\node_modules\mongodb\lib\utils.js:371:9
        at C:\Users\user\Desktop\Leobinus\node_modules\mongodb\lib\sessions.js:136:24
        at maybePromise (C:\Users\user\Desktop\Leobinus\node_modules\mongodb\lib\utils.js:357:5)
        at ClientSession.endSession (C:\Users\user\Desktop\Leobinus\node_modules\mongodb\lib\sessions.js:133:41)
        at cleanupCursor (C:\Users\user\Desktop\Leobinus\node_modules\mongodb\lib\cursor\abstract_cursor.js:557:32) {
      errno: -4058,
      syscall: 'unlink',
      code: 'ENOENT',
      path: './public/image/1670206975768E_NICE_0.jpg'
    }
    [nodemon] app crashed - waiting for file changes before starting...
    이러고 서버가 멈춰서 수동으로 꺼주고 재시작하면 정상 삭제 되는데, 어느 부분이 충돌한것입니까..?
    
    // 코드첨부
    var allsrc = [];
    app.delete('/deltab', (req, res)=>{
      db.collection('post').find({category : req.body.category}).toArray((error, result)=>{
        if(result.length === 0){
          db.collection('category').deleteOne({category : req.body.category},(error, result)=>{
            if(error) { return res.send(error) }
            return res.send('게시물 없는 카테고리 삭제');
          })
        } else {
          for(let i=0; i<result.length; i++){
            if(typeof result[i].src === 'string'){
              allsrc.push(result[i].src);
            } else if(typeof result[i].src ==='object'){
              allsrc.push(...result[i].src);
            }
          }
          for(let i=0; i<allsrc.length; i++){
            fs.unlinkSync(`./public/image/${allsrc[i]}`);
          }
          db.collection('post').deleteMany({category : req.body.category},(error, result)=>{
            if(error) { return res.send(error) }
            console.log('good');
          })
          db.collection('category').deleteOne({category : req.body.category},(error, result)=>{
            if(error) { return res.send(error) }
            return res.send('게시물있는 카테고리 삭제');
          })
        }
      })
    })
    
    
    삭제 다 했으면 db를 초기화? 재시작 시켜야하는 그런 방법으 있을까요 센세..!?
    #56891

    codingapple
    키 마스터
    var allsrc = [] 를 출력해보거나 app.delete 안으로 옮겨봅시다
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 호 / 개인정보관리자 : 박종흠